blob: 8431dda2292e0f8ae8e3153322f7136cbc8ffbc7 [file] [log] [blame]
George Liu6492f522020-06-16 10:34:05 +08001#include "libpldm/base.h"
2#include "libpldm/bios.h"
3#include "libpldm/pdr.h"
4#include "libpldm/platform.h"
5
Deepak Kodihallid130e1a2020-06-17 05:55:32 -05006#include "common/utils.hpp"
Deepak Kodihalli4de4d002019-11-11 02:41:43 -06007#include "dbus_impl_requester.hpp"
Deepak Kodihallibc669f12019-11-28 08:52:07 -06008#include "invoker.hpp"
Tom Joseph74f27c72021-05-16 07:58:53 -07009#include "requester/handler.hpp"
10#include "requester/request.hpp"
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050011
12#include <err.h>
Jinu Joy Thomas75dd4422019-07-22 12:47:12 +053013#include <getopt.h>
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050014#include <poll.h>
15#include <stdlib.h>
16#include <sys/socket.h>
17#include <sys/types.h>
18#include <sys/un.h>
19#include <unistd.h>
20
George Liu6492f522020-06-16 10:34:05 +080021#include <sdeventplus/event.hpp>
22#include <sdeventplus/source/io.hpp>
23
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050024#include <cstdio>
25#include <cstring>
Pavithra Barithaya51efaf82020-04-02 02:42:27 -050026#include <fstream>
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050027#include <iomanip>
Jinu Joy Thomas75dd4422019-07-22 12:47:12 +053028#include <iostream>
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050029#include <iterator>
Deepak Kodihallic682fe22020-03-04 00:42:54 -060030#include <memory>
Tom Joseph74f27c72021-05-16 07:58:53 -070031#include <optional>
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050032#include <sstream>
Deepak Kodihallibc669f12019-11-28 08:52:07 -060033#include <stdexcept>
Jinu Joy Thomas75dd4422019-07-22 12:47:12 +053034#include <string>
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050035#include <vector>
36
Tom Joseph02b4ee42021-05-02 22:44:36 -070037#ifdef LIBPLDMRESPONDER
38#include "dbus_impl_pdr.hpp"
39#include "host-bmc/dbus_to_event_handler.hpp"
40#include "host-bmc/dbus_to_host_effecters.hpp"
Tom Joseph20aa3e02021-08-17 04:44:19 -070041#include "host-bmc/host_condition.hpp"
Tom Joseph02b4ee42021-05-02 22:44:36 -070042#include "host-bmc/host_pdr_handler.hpp"
43#include "libpldmresponder/base.hpp"
44#include "libpldmresponder/bios.hpp"
45#include "libpldmresponder/fru.hpp"
46#include "libpldmresponder/oem_handler.hpp"
47#include "libpldmresponder/platform.hpp"
48#include "xyz/openbmc_project/PLDM/Event/server.hpp"
49#endif
50
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050051#ifdef OEM_IBM
52#include "libpldmresponder/file_io.hpp"
Sampa Misraaea5dde2020-08-31 08:33:47 -050053#include "libpldmresponder/oem_ibm_handler.hpp"
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050054#endif
55
56constexpr uint8_t MCTP_MSG_TYPE_PLDM = 1;
57
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050058using namespace pldm;
Deepak Kodihalli37998bf2019-11-11 04:06:53 -060059using namespace sdeventplus;
60using namespace sdeventplus::source;
Tom Joseph02b4ee42021-05-02 22:44:36 -070061using namespace pldm::responder;
62using namespace pldm::utils;
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050063
Tom Joseph74f27c72021-05-16 07:58:53 -070064static std::optional<Response>
65 processRxMsg(const std::vector<uint8_t>& requestMsg, Invoker& invoker,
66 requester::Handler<requester::Request>& handler)
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050067{
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050068 uint8_t eid = requestMsg[0];
69 uint8_t type = requestMsg[1];
70 pldm_header_info hdrFields{};
71 auto hdr = reinterpret_cast<const pldm_msg_hdr*>(
72 requestMsg.data() + sizeof(eid) + sizeof(type));
73 if (PLDM_SUCCESS != unpack_pldm_header(hdr, &hdrFields))
74 {
Sampa Misraaa8ae722019-12-12 03:20:40 -060075 std::cerr << "Empty PLDM request header \n";
Tom Joseph74f27c72021-05-16 07:58:53 -070076 return std::nullopt;
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050077 }
George Liub7095ff2021-06-14 16:01:57 +080078
79 if (PLDM_RESPONSE != hdrFields.msg_type)
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050080 {
Tom Joseph74f27c72021-05-16 07:58:53 -070081 Response response;
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050082 auto request = reinterpret_cast<const pldm_msg*>(hdr);
83 size_t requestLen = requestMsg.size() - sizeof(struct pldm_msg_hdr) -
84 sizeof(eid) - sizeof(type);
Deepak Kodihallibc669f12019-11-28 08:52:07 -060085 try
86 {
87 response = invoker.handle(hdrFields.pldm_type, hdrFields.command,
88 request, requestLen);
89 }
90 catch (const std::out_of_range& e)
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050091 {
92 uint8_t completion_code = PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
93 response.resize(sizeof(pldm_msg_hdr));
94 auto responseHdr = reinterpret_cast<pldm_msg_hdr*>(response.data());
95 pldm_header_info header{};
96 header.msg_type = PLDM_RESPONSE;
97 header.instance = hdrFields.instance;
98 header.pldm_type = hdrFields.pldm_type;
99 header.command = hdrFields.command;
George Liub7095ff2021-06-14 16:01:57 +0800100 if (PLDM_SUCCESS != pack_pldm_header(&header, responseHdr))
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500101 {
Sampa Misraaa8ae722019-12-12 03:20:40 -0600102 std::cerr << "Failed adding response header \n";
Tom Joseph74f27c72021-05-16 07:58:53 -0700103 return std::nullopt;
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500104 }
105 response.insert(response.end(), completion_code);
106 }
Tom Joseph74f27c72021-05-16 07:58:53 -0700107 return response;
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500108 }
Tom Joseph74f27c72021-05-16 07:58:53 -0700109 else if (PLDM_RESPONSE == hdrFields.msg_type)
Deepak Kodihalli4de4d002019-11-11 02:41:43 -0600110 {
Tom Joseph74f27c72021-05-16 07:58:53 -0700111 auto response = reinterpret_cast<const pldm_msg*>(hdr);
112 size_t responseLen = requestMsg.size() - sizeof(struct pldm_msg_hdr) -
113 sizeof(eid) - sizeof(type);
114 handler.handleResponse(eid, hdrFields.instance, hdrFields.pldm_type,
115 hdrFields.command, response, responseLen);
Deepak Kodihalli4de4d002019-11-11 02:41:43 -0600116 }
Tom Joseph74f27c72021-05-16 07:58:53 -0700117 return std::nullopt;
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500118}
119
Jinu Joy Thomas75dd4422019-07-22 12:47:12 +0530120void optionUsage(void)
121{
122 std::cerr << "Usage: pldmd [options]\n";
123 std::cerr << "Options:\n";
124 std::cerr
125 << " --verbose=<0/1> 0 - Disable verbosity, 1 - Enable verbosity\n";
126 std::cerr << "Defaulted settings: --verbose=0 \n";
127}
128
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500129int main(int argc, char** argv)
130{
131
Jinu Joy Thomas75dd4422019-07-22 12:47:12 +0530132 bool verbose = false;
133 static struct option long_options[] = {
134 {"verbose", required_argument, 0, 'v'}, {0, 0, 0, 0}};
135
136 auto argflag = getopt_long(argc, argv, "v:", long_options, nullptr);
137 switch (argflag)
138 {
139 case 'v':
140 switch (std::stoi(optarg))
141 {
142 case 0:
143 verbose = false;
144 break;
145 case 1:
146 verbose = true;
147 break;
148 default:
149 optionUsage();
150 break;
151 }
152 break;
153 default:
154 optionUsage();
155 break;
156 }
157
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500158 /* Create local socket. */
159 int returnCode = 0;
160 int sockfd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
161 if (-1 == sockfd)
162 {
163 returnCode = -errno;
Sampa Misraaa8ae722019-12-12 03:20:40 -0600164 std::cerr << "Failed to create the socket, RC= " << returnCode << "\n";
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500165 exit(EXIT_FAILURE);
166 }
167
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500168 auto event = Event::get_default();
Tom Joseph02b4ee42021-05-02 22:44:36 -0700169 auto& bus = pldm::utils::DBusHandler::getBus();
170 dbus_api::Requester dbusImplReq(bus, "/xyz/openbmc_project/pldm");
Pavithra Barithaya319ebb32021-05-06 06:09:11 -0500171
Tom Joseph02b4ee42021-05-02 22:44:36 -0700172 Invoker invoker{};
Tom Joseph74f27c72021-05-16 07:58:53 -0700173 requester::Handler<requester::Request> reqHandler(sockfd, event,
Tom Josephe5268cd2021-09-07 13:04:03 +0530174 dbusImplReq, verbose);
Tom Joseph02b4ee42021-05-02 22:44:36 -0700175
176#ifdef LIBPLDMRESPONDER
177 using namespace pldm::state_sensor;
Tom Joseph20aa3e02021-08-17 04:44:19 -0700178 dbus_api::Host dbusImplHost(bus, "/xyz/openbmc_project/pldm");
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500179 std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)> pdrRepo(
180 pldm_pdr_init(), pldm_pdr_destroy);
181 std::unique_ptr<pldm_entity_association_tree,
182 decltype(&pldm_entity_association_tree_destroy)>
183 entityTree(pldm_entity_association_tree_init(),
184 pldm_entity_association_tree_destroy);
Sampa Misrac073a202021-05-08 10:56:05 -0500185 std::unique_ptr<pldm_entity_association_tree,
186 decltype(&pldm_entity_association_tree_destroy)>
187 bmcEntityTree(pldm_entity_association_tree_init(),
188 pldm_entity_association_tree_destroy);
Pavithra Barithaya319ebb32021-05-06 06:09:11 -0500189 std::shared_ptr<HostPDRHandler> hostPDRHandler;
Sampa Misrac0c60542020-07-01 02:34:25 -0500190 std::unique_ptr<pldm::host_effecters::HostEffecterParser>
191 hostEffecterParser;
George Liucae18662020-05-15 09:32:57 +0800192 std::unique_ptr<DbusToPLDMEvent> dbusToPLDMEventHandler;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500193 auto dbusHandler = std::make_unique<DBusHandler>();
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500194 auto hostEID = pldm::utils::readHostEID();
195 if (hostEID)
196 {
Pavithra Barithaya319ebb32021-05-06 06:09:11 -0500197 hostPDRHandler = std::make_shared<HostPDRHandler>(
Pavithra Barithaya3aec9972020-12-14 01:55:44 -0600198 sockfd, hostEID, event, pdrRepo.get(), EVENTS_JSONS_DIR,
Tom Josephe5268cd2021-09-07 13:04:03 +0530199 entityTree.get(), bmcEntityTree.get(), dbusImplReq, &reqHandler);
Pavithra Barithaya319ebb32021-05-06 06:09:11 -0500200 // HostFirmware interface needs access to hostPDR to know if host
201 // is running
202 dbusImplHost.setHostPdrObj(hostPDRHandler);
203
Sampa Misrac0c60542020-07-01 02:34:25 -0500204 hostEffecterParser =
205 std::make_unique<pldm::host_effecters::HostEffecterParser>(
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500206 &dbusImplReq, sockfd, pdrRepo.get(), dbusHandler.get(),
Tom Josephe5268cd2021-09-07 13:04:03 +0530207 HOST_JSONS_DIR, &reqHandler);
Sampa Misrac0c79482021-06-02 08:01:54 -0500208 dbusToPLDMEventHandler = std::make_unique<DbusToPLDMEvent>(
209 sockfd, hostEID, dbusImplReq, &reqHandler);
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500210 }
Sampa Misraaea5dde2020-08-31 08:33:47 -0500211 std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
212
213#ifdef OEM_IBM
214 std::unique_ptr<pldm::responder::CodeUpdate> codeUpdate =
215 std::make_unique<pldm::responder::CodeUpdate>(dbusHandler.get());
Varsha Kaverappa3ca29df2020-09-27 12:39:22 -0500216 codeUpdate->clearDirPath(LID_STAGING_DIR);
Sampa Misraaea5dde2020-08-31 08:33:47 -0500217 oemPlatformHandler = std::make_unique<oem_ibm_platform::Handler>(
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500218 dbusHandler.get(), codeUpdate.get(), sockfd, hostEID, dbusImplReq,
Sampa Misrac0c79482021-06-02 08:01:54 -0500219 event, &reqHandler);
Sampa Misraaea5dde2020-08-31 08:33:47 -0500220 codeUpdate->setOemPlatformHandler(oemPlatformHandler.get());
Sampa Misrac0c79482021-06-02 08:01:54 -0500221 invoker.registerHandler(PLDM_OEM, std::make_unique<oem_ibm::Handler>(
222 oemPlatformHandler.get(), sockfd,
223 hostEID, &dbusImplReq, &reqHandler));
Sampa Misraaea5dde2020-08-31 08:33:47 -0500224#endif
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -0500225 invoker.registerHandler(
Sampa Misrac0c79482021-06-02 08:01:54 -0500226 PLDM_BIOS, std::make_unique<bios::Handler>(sockfd, hostEID,
227 &dbusImplReq, &reqHandler));
Tom Joseph33e9c7e2020-06-11 22:09:52 +0530228 auto fruHandler = std::make_unique<fru::Handler>(
Manojkiran Eda03b01ca2021-06-29 08:55:09 +0530229 FRU_JSONS_DIR, FRU_MASTER_JSON, pdrRepo.get(), entityTree.get(),
230 bmcEntityTree.get());
Tom Joseph33e9c7e2020-06-11 22:09:52 +0530231 // FRU table is built lazily when a FRU command or Get PDR command is
232 // handled. To enable building FRU table, the FRU handler is passed to the
233 // Platform handler.
Sampa Misraaea5dde2020-08-31 08:33:47 -0500234 auto platformHandler = std::make_unique<platform::Handler>(
235 dbusHandler.get(), PDR_JSONS_DIR, pdrRepo.get(), hostPDRHandler.get(),
236 dbusToPLDMEventHandler.get(), fruHandler.get(),
Sampa Misra5fb37d52021-03-06 07:26:00 -0600237 oemPlatformHandler.get(), event, true);
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500238#ifdef OEM_IBM
Sampa Misraaea5dde2020-08-31 08:33:47 -0500239 pldm::responder::oem_ibm_platform::Handler* oemIbmPlatformHandler =
240 dynamic_cast<pldm::responder::oem_ibm_platform::Handler*>(
241 oemPlatformHandler.get());
242 oemIbmPlatformHandler->setPlatformHandler(platformHandler.get());
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500243#endif
244
Sampa Misraaea5dde2020-08-31 08:33:47 -0500245 invoker.registerHandler(PLDM_PLATFORM, std::move(platformHandler));
Sagar Srinivas79669c92021-04-28 15:43:30 -0500246 invoker.registerHandler(
247 PLDM_BASE,
248 std::make_unique<base::Handler>(hostEID, dbusImplReq, event,
249 oemPlatformHandler.get(), &reqHandler));
Sampa Misraaea5dde2020-08-31 08:33:47 -0500250 invoker.registerHandler(PLDM_FRU, std::move(fruHandler));
Tom Joseph02b4ee42021-05-02 22:44:36 -0700251 dbus_api::Pdr dbusImplPdr(bus, "/xyz/openbmc_project/pldm", pdrRepo.get());
252 sdbusplus::xyz::openbmc_project::PLDM::server::Event dbusImplEvent(
253 bus, "/xyz/openbmc_project/pldm");
Tom Joseph20aa3e02021-08-17 04:44:19 -0700254
Tom Joseph02b4ee42021-05-02 22:44:36 -0700255#endif
Sampa Misraaea5dde2020-08-31 08:33:47 -0500256
George Liu83409572019-12-24 18:42:54 +0800257 pldm::utils::CustomFD socketFd(sockfd);
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500258
259 struct sockaddr_un addr
George Liu6492f522020-06-16 10:34:05 +0800260 {};
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500261 addr.sun_family = AF_UNIX;
262 const char path[] = "\0mctp-mux";
263 memcpy(addr.sun_path, path, sizeof(path) - 1);
264 int result = connect(socketFd(), reinterpret_cast<struct sockaddr*>(&addr),
265 sizeof(path) + sizeof(addr.sun_family) - 1);
266 if (-1 == result)
267 {
268 returnCode = -errno;
Sampa Misraaa8ae722019-12-12 03:20:40 -0600269 std::cerr << "Failed to connect to the socket, RC= " << returnCode
270 << "\n";
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500271 exit(EXIT_FAILURE);
272 }
273
274 result = write(socketFd(), &MCTP_MSG_TYPE_PLDM, sizeof(MCTP_MSG_TYPE_PLDM));
275 if (-1 == result)
276 {
277 returnCode = -errno;
Sampa Misraaa8ae722019-12-12 03:20:40 -0600278 std::cerr << "Failed to send message type as pldm to mctp, RC= "
279 << returnCode << "\n";
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500280 exit(EXIT_FAILURE);
281 }
282
Tom Joseph74f27c72021-05-16 07:58:53 -0700283 auto callback = [verbose, &invoker, &reqHandler](IO& io, int fd,
284 uint32_t revents) {
Deepak Kodihalli37998bf2019-11-11 04:06:53 -0600285 if (!(revents & EPOLLIN))
286 {
287 return;
288 }
289
290 // Outgoing message.
291 struct iovec iov[2]{};
292
293 // This structure contains the parameter information for the response
294 // message.
295 struct msghdr msg
George Liu6492f522020-06-16 10:34:05 +0800296 {};
Deepak Kodihalli37998bf2019-11-11 04:06:53 -0600297
298 int returnCode = 0;
299 ssize_t peekedLength = recv(fd, nullptr, 0, MSG_PEEK | MSG_TRUNC);
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500300 if (0 == peekedLength)
301 {
Deepak Kodihalli23c52042020-09-01 03:04:32 -0500302 // MCTP daemon has closed the socket this daemon is connected to.
303 // This may or may not be an error scenario, in either case the
304 // recovery mechanism for this daemon is to restart, and hence exit
305 // the event loop, that will cause this daemon to exit with a
306 // failure code.
307 io.get_event().exit(0);
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500308 }
309 else if (peekedLength <= -1)
310 {
311 returnCode = -errno;
Sampa Misraaa8ae722019-12-12 03:20:40 -0600312 std::cerr << "recv system call failed, RC= " << returnCode << "\n";
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500313 }
314 else
315 {
316 std::vector<uint8_t> requestMsg(peekedLength);
317 auto recvDataLength = recv(
Deepak Kodihalli37998bf2019-11-11 04:06:53 -0600318 fd, static_cast<void*>(requestMsg.data()), peekedLength, 0);
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500319 if (recvDataLength == peekedLength)
320 {
Jinu Joy Thomas75dd4422019-07-22 12:47:12 +0530321 if (verbose)
322 {
Tom Josephe5268cd2021-09-07 13:04:03 +0530323 printBuffer(Rx, requestMsg);
Jinu Joy Thomas75dd4422019-07-22 12:47:12 +0530324 }
Tom Josephe5268cd2021-09-07 13:04:03 +0530325
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500326 if (MCTP_MSG_TYPE_PLDM != requestMsg[1])
327 {
328 // Skip this message and continue.
Sampa Misraaa8ae722019-12-12 03:20:40 -0600329 std::cerr << "Encountered Non-PLDM type message"
330 << "\n";
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500331 }
332 else
333 {
334 // process message and send response
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600335 auto response =
Tom Joseph74f27c72021-05-16 07:58:53 -0700336 processRxMsg(requestMsg, invoker, reqHandler);
337 if (response.has_value())
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500338 {
Deepak Kodihalli8ffbbe02019-08-14 06:51:38 -0500339 if (verbose)
340 {
Tom Josephe5268cd2021-09-07 13:04:03 +0530341 printBuffer(Tx, *response);
Deepak Kodihalli8ffbbe02019-08-14 06:51:38 -0500342 }
343
Zahed Hossain09a96e02019-08-06 07:42:37 -0500344 iov[0].iov_base = &requestMsg[0];
345 iov[0].iov_len =
346 sizeof(requestMsg[0]) + sizeof(requestMsg[1]);
Tom Joseph74f27c72021-05-16 07:58:53 -0700347 iov[1].iov_base = (*response).data();
348 iov[1].iov_len = (*response).size();
Zahed Hossain09a96e02019-08-06 07:42:37 -0500349
350 msg.msg_iov = iov;
351 msg.msg_iovlen = sizeof(iov) / sizeof(iov[0]);
352
Deepak Kodihalli37998bf2019-11-11 04:06:53 -0600353 int result = sendmsg(fd, &msg, 0);
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500354 if (-1 == result)
355 {
356 returnCode = -errno;
Sampa Misraaa8ae722019-12-12 03:20:40 -0600357 std::cerr << "sendto system call failed, RC= "
358 << returnCode << "\n";
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500359 }
360 }
361 }
362 }
363 else
364 {
Sampa Misraaa8ae722019-12-12 03:20:40 -0600365 std::cerr
366 << "Failure to read peeked length packet. peekedLength= "
367 << peekedLength << " recvDataLength=" << recvDataLength
368 << "\n";
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500369 }
370 }
Deepak Kodihalli37998bf2019-11-11 04:06:53 -0600371 };
372
Deepak Kodihalli4de4d002019-11-11 02:41:43 -0600373 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
374 bus.request_name("xyz.openbmc_project.PLDM");
Deepak Kodihalli37998bf2019-11-11 04:06:53 -0600375 IO io(event, socketFd(), EPOLLIN, std::move(callback));
Manojkiran Eda88bc7182021-09-08 18:37:30 +0530376#ifdef LIBPLDMRESPONDER
377 if (hostPDRHandler)
378 {
379 hostPDRHandler->setHostFirmwareCondition();
380 }
381#endif
Deepak Kodihalli37998bf2019-11-11 04:06:53 -0600382 event.loop();
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500383
384 result = shutdown(sockfd, SHUT_RDWR);
385 if (-1 == result)
386 {
387 returnCode = -errno;
Sampa Misraaa8ae722019-12-12 03:20:40 -0600388 std::cerr << "Failed to shutdown the socket, RC=" << returnCode << "\n";
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500389 exit(EXIT_FAILURE);
390 }
391 exit(EXIT_FAILURE);
392}