George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 1 | #include "libpldm/base.h" |
| 2 | #include "libpldm/bios.h" |
| 3 | #include "libpldm/pdr.h" |
| 4 | #include "libpldm/platform.h" |
| 5 | |
Deepak Kodihalli | d130e1a | 2020-06-17 05:55:32 -0500 | [diff] [blame] | 6 | #include "common/utils.hpp" |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 7 | #include "dbus_impl_pdr.hpp" |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 8 | #include "dbus_impl_requester.hpp" |
Deepak Kodihalli | ac19bd6 | 2020-06-16 08:25:23 -0500 | [diff] [blame] | 9 | #include "host-bmc/dbus_to_host_effecters.hpp" |
| 10 | #include "host-bmc/host_pdr_handler.hpp" |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 11 | #include "invoker.hpp" |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 12 | #include "libpldmresponder/base.hpp" |
| 13 | #include "libpldmresponder/bios.hpp" |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 14 | #include "libpldmresponder/fru.hpp" |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 15 | #include "libpldmresponder/platform.hpp" |
Chicago Duan | 174665f | 2020-07-08 17:41:05 +0800 | [diff] [blame] | 16 | #include "xyz/openbmc_project/PLDM/Event/server.hpp" |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 17 | |
| 18 | #include <err.h> |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 19 | #include <getopt.h> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 20 | #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 | |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 27 | #include <sdeventplus/event.hpp> |
| 28 | #include <sdeventplus/source/io.hpp> |
| 29 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 30 | #include <cstdio> |
| 31 | #include <cstring> |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 32 | #include <fstream> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 33 | #include <iomanip> |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 34 | #include <iostream> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 35 | #include <iterator> |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 36 | #include <memory> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 37 | #include <sstream> |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 38 | #include <stdexcept> |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 39 | #include <string> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 40 | #include <vector> |
| 41 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 42 | #ifdef OEM_IBM |
| 43 | #include "libpldmresponder/file_io.hpp" |
| 44 | #endif |
| 45 | |
| 46 | constexpr uint8_t MCTP_MSG_TYPE_PLDM = 1; |
| 47 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 48 | using namespace pldm::responder; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 49 | using namespace pldm; |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 50 | using namespace sdeventplus; |
| 51 | using namespace sdeventplus::source; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 52 | |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 53 | static Response processRxMsg(const std::vector<uint8_t>& requestMsg, |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 54 | Invoker& invoker, dbus_api::Requester& requester) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 55 | { |
| 56 | |
| 57 | Response response; |
| 58 | uint8_t eid = requestMsg[0]; |
| 59 | uint8_t type = requestMsg[1]; |
| 60 | pldm_header_info hdrFields{}; |
| 61 | auto hdr = reinterpret_cast<const pldm_msg_hdr*>( |
| 62 | requestMsg.data() + sizeof(eid) + sizeof(type)); |
| 63 | if (PLDM_SUCCESS != unpack_pldm_header(hdr, &hdrFields)) |
| 64 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 65 | std::cerr << "Empty PLDM request header \n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 66 | } |
| 67 | else if (PLDM_RESPONSE != hdrFields.msg_type) |
| 68 | { |
| 69 | auto request = reinterpret_cast<const pldm_msg*>(hdr); |
| 70 | size_t requestLen = requestMsg.size() - sizeof(struct pldm_msg_hdr) - |
| 71 | sizeof(eid) - sizeof(type); |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 72 | try |
| 73 | { |
| 74 | response = invoker.handle(hdrFields.pldm_type, hdrFields.command, |
| 75 | request, requestLen); |
| 76 | } |
| 77 | catch (const std::out_of_range& e) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 78 | { |
| 79 | uint8_t completion_code = PLDM_ERROR_UNSUPPORTED_PLDM_CMD; |
| 80 | response.resize(sizeof(pldm_msg_hdr)); |
| 81 | auto responseHdr = reinterpret_cast<pldm_msg_hdr*>(response.data()); |
| 82 | pldm_header_info header{}; |
| 83 | header.msg_type = PLDM_RESPONSE; |
| 84 | header.instance = hdrFields.instance; |
| 85 | header.pldm_type = hdrFields.pldm_type; |
| 86 | header.command = hdrFields.command; |
| 87 | auto result = pack_pldm_header(&header, responseHdr); |
| 88 | if (PLDM_SUCCESS != result) |
| 89 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 90 | std::cerr << "Failed adding response header \n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 91 | } |
| 92 | response.insert(response.end(), completion_code); |
| 93 | } |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 94 | } |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 95 | else |
| 96 | { |
| 97 | requester.markFree(eid, hdr->instance_id); |
| 98 | } |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 99 | return response; |
| 100 | } |
| 101 | |
| 102 | void printBuffer(const std::vector<uint8_t>& buffer) |
| 103 | { |
| 104 | std::ostringstream tempStream; |
| 105 | tempStream << "Buffer Data: "; |
| 106 | if (!buffer.empty()) |
| 107 | { |
| 108 | for (int byte : buffer) |
| 109 | { |
| 110 | tempStream << std::setfill('0') << std::setw(2) << std::hex << byte |
| 111 | << " "; |
| 112 | } |
| 113 | } |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 114 | std::cout << tempStream.str().c_str() << std::endl; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 115 | } |
| 116 | |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 117 | void optionUsage(void) |
| 118 | { |
| 119 | std::cerr << "Usage: pldmd [options]\n"; |
| 120 | std::cerr << "Options:\n"; |
| 121 | std::cerr |
| 122 | << " --verbose=<0/1> 0 - Disable verbosity, 1 - Enable verbosity\n"; |
| 123 | std::cerr << "Defaulted settings: --verbose=0 \n"; |
| 124 | } |
| 125 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 126 | int main(int argc, char** argv) |
| 127 | { |
| 128 | |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 129 | bool verbose = false; |
| 130 | static struct option long_options[] = { |
| 131 | {"verbose", required_argument, 0, 'v'}, {0, 0, 0, 0}}; |
| 132 | |
| 133 | auto argflag = getopt_long(argc, argv, "v:", long_options, nullptr); |
| 134 | switch (argflag) |
| 135 | { |
| 136 | case 'v': |
| 137 | switch (std::stoi(optarg)) |
| 138 | { |
| 139 | case 0: |
| 140 | verbose = false; |
| 141 | break; |
| 142 | case 1: |
| 143 | verbose = true; |
| 144 | break; |
| 145 | default: |
| 146 | optionUsage(); |
| 147 | break; |
| 148 | } |
| 149 | break; |
| 150 | default: |
| 151 | optionUsage(); |
| 152 | break; |
| 153 | } |
| 154 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 155 | /* Create local socket. */ |
| 156 | int returnCode = 0; |
| 157 | int sockfd = socket(AF_UNIX, SOCK_SEQPACKET, 0); |
| 158 | if (-1 == sockfd) |
| 159 | { |
| 160 | returnCode = -errno; |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 161 | std::cerr << "Failed to create the socket, RC= " << returnCode << "\n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 162 | exit(EXIT_FAILURE); |
| 163 | } |
| 164 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 165 | auto event = Event::get_default(); |
| 166 | std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)> pdrRepo( |
| 167 | pldm_pdr_init(), pldm_pdr_destroy); |
| 168 | std::unique_ptr<pldm_entity_association_tree, |
| 169 | decltype(&pldm_entity_association_tree_destroy)> |
| 170 | entityTree(pldm_entity_association_tree_init(), |
| 171 | pldm_entity_association_tree_destroy); |
| 172 | auto& bus = pldm::utils::DBusHandler::getBus(); |
| 173 | dbus_api::Requester dbusImplReq(bus, "/xyz/openbmc_project/pldm"); |
| 174 | std::unique_ptr<HostPDRHandler> hostPDRHandler; |
Sampa Misra | c0c6054 | 2020-07-01 02:34:25 -0500 | [diff] [blame] | 175 | std::unique_ptr<pldm::host_effecters::HostEffecterParser> |
| 176 | hostEffecterParser; |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 177 | auto dbusHandler = std::make_unique<DBusHandler>(); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 178 | auto hostEID = pldm::utils::readHostEID(); |
| 179 | if (hostEID) |
| 180 | { |
| 181 | hostPDRHandler = std::make_unique<HostPDRHandler>( |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 182 | sockfd, hostEID, event, pdrRepo.get(), entityTree.get(), |
| 183 | dbusImplReq); |
Sampa Misra | c0c6054 | 2020-07-01 02:34:25 -0500 | [diff] [blame] | 184 | hostEffecterParser = |
| 185 | std::make_unique<pldm::host_effecters::HostEffecterParser>( |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 186 | &dbusImplReq, sockfd, pdrRepo.get(), dbusHandler.get(), |
Sampa Misra | c0c6054 | 2020-07-01 02:34:25 -0500 | [diff] [blame] | 187 | HOST_JSONS_DIR, verbose); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | Invoker invoker{}; |
| 191 | invoker.registerHandler(PLDM_BASE, std::make_unique<base::Handler>()); |
| 192 | invoker.registerHandler(PLDM_BIOS, std::make_unique<bios::Handler>()); |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 193 | auto fruHandler = std::make_unique<fru::Handler>( |
| 194 | FRU_JSONS_DIR, pdrRepo.get(), entityTree.get()); |
| 195 | // FRU table is built lazily when a FRU command or Get PDR command is |
| 196 | // handled. To enable building FRU table, the FRU handler is passed to the |
| 197 | // Platform handler. |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 198 | invoker.registerHandler(PLDM_PLATFORM, |
| 199 | std::make_unique<platform::Handler>( |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 200 | dbusHandler.get(), PDR_JSONS_DIR, |
| 201 | EVENTS_JSONS_DIR, pdrRepo.get(), |
| 202 | hostPDRHandler.get(), fruHandler.get(), true)); |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 203 | invoker.registerHandler(PLDM_FRU, std::move(fruHandler)); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 204 | |
| 205 | #ifdef OEM_IBM |
| 206 | invoker.registerHandler(PLDM_OEM, std::make_unique<oem_ibm::Handler>()); |
| 207 | #endif |
| 208 | |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 209 | pldm::utils::CustomFD socketFd(sockfd); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 210 | |
| 211 | struct sockaddr_un addr |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 212 | {}; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 213 | addr.sun_family = AF_UNIX; |
| 214 | const char path[] = "\0mctp-mux"; |
| 215 | memcpy(addr.sun_path, path, sizeof(path) - 1); |
| 216 | int result = connect(socketFd(), reinterpret_cast<struct sockaddr*>(&addr), |
| 217 | sizeof(path) + sizeof(addr.sun_family) - 1); |
| 218 | if (-1 == result) |
| 219 | { |
| 220 | returnCode = -errno; |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 221 | std::cerr << "Failed to connect to the socket, RC= " << returnCode |
| 222 | << "\n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 223 | exit(EXIT_FAILURE); |
| 224 | } |
| 225 | |
| 226 | result = write(socketFd(), &MCTP_MSG_TYPE_PLDM, sizeof(MCTP_MSG_TYPE_PLDM)); |
| 227 | if (-1 == result) |
| 228 | { |
| 229 | returnCode = -errno; |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 230 | std::cerr << "Failed to send message type as pldm to mctp, RC= " |
| 231 | << returnCode << "\n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 232 | exit(EXIT_FAILURE); |
| 233 | } |
| 234 | |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 235 | dbus_api::Pdr dbusImplPdr(bus, "/xyz/openbmc_project/pldm", pdrRepo.get()); |
Chicago Duan | 174665f | 2020-07-08 17:41:05 +0800 | [diff] [blame] | 236 | sdbusplus::xyz::openbmc_project::PLDM::server::Event dbusImplEvent( |
| 237 | bus, "/xyz/openbmc_project/pldm"); |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 238 | auto callback = [verbose, &invoker, &dbusImplReq](IO& /*io*/, int fd, |
| 239 | uint32_t revents) { |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 240 | if (!(revents & EPOLLIN)) |
| 241 | { |
| 242 | return; |
| 243 | } |
| 244 | |
| 245 | // Outgoing message. |
| 246 | struct iovec iov[2]{}; |
| 247 | |
| 248 | // This structure contains the parameter information for the response |
| 249 | // message. |
| 250 | struct msghdr msg |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 251 | {}; |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 252 | |
| 253 | int returnCode = 0; |
| 254 | ssize_t peekedLength = recv(fd, nullptr, 0, MSG_PEEK | MSG_TRUNC); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 255 | if (0 == peekedLength) |
| 256 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 257 | std::cerr << "Socket has been closed \n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 258 | } |
| 259 | else if (peekedLength <= -1) |
| 260 | { |
| 261 | returnCode = -errno; |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 262 | std::cerr << "recv system call failed, RC= " << returnCode << "\n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 263 | } |
| 264 | else |
| 265 | { |
| 266 | std::vector<uint8_t> requestMsg(peekedLength); |
| 267 | auto recvDataLength = recv( |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 268 | fd, static_cast<void*>(requestMsg.data()), peekedLength, 0); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 269 | if (recvDataLength == peekedLength) |
| 270 | { |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 271 | if (verbose) |
| 272 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 273 | std::cout << "Received Msg" << std::endl; |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 274 | printBuffer(requestMsg); |
| 275 | } |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 276 | if (MCTP_MSG_TYPE_PLDM != requestMsg[1]) |
| 277 | { |
| 278 | // Skip this message and continue. |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 279 | std::cerr << "Encountered Non-PLDM type message" |
| 280 | << "\n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 281 | } |
| 282 | else |
| 283 | { |
| 284 | // process message and send response |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 285 | auto response = |
| 286 | processRxMsg(requestMsg, invoker, dbusImplReq); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 287 | if (!response.empty()) |
| 288 | { |
Deepak Kodihalli | 8ffbbe0 | 2019-08-14 06:51:38 -0500 | [diff] [blame] | 289 | if (verbose) |
| 290 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 291 | std::cout << "Sending Msg" << std::endl; |
Deepak Kodihalli | 8ffbbe0 | 2019-08-14 06:51:38 -0500 | [diff] [blame] | 292 | printBuffer(response); |
| 293 | } |
| 294 | |
Zahed Hossain | 09a96e0 | 2019-08-06 07:42:37 -0500 | [diff] [blame] | 295 | iov[0].iov_base = &requestMsg[0]; |
| 296 | iov[0].iov_len = |
| 297 | sizeof(requestMsg[0]) + sizeof(requestMsg[1]); |
| 298 | iov[1].iov_base = response.data(); |
| 299 | iov[1].iov_len = response.size(); |
| 300 | |
| 301 | msg.msg_iov = iov; |
| 302 | msg.msg_iovlen = sizeof(iov) / sizeof(iov[0]); |
| 303 | |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 304 | int result = sendmsg(fd, &msg, 0); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 305 | if (-1 == result) |
| 306 | { |
| 307 | returnCode = -errno; |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 308 | std::cerr << "sendto system call failed, RC= " |
| 309 | << returnCode << "\n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | else |
| 315 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 316 | std::cerr |
| 317 | << "Failure to read peeked length packet. peekedLength= " |
| 318 | << peekedLength << " recvDataLength=" << recvDataLength |
| 319 | << "\n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 320 | } |
| 321 | } |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 322 | }; |
| 323 | |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 324 | bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); |
| 325 | bus.request_name("xyz.openbmc_project.PLDM"); |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 326 | IO io(event, socketFd(), EPOLLIN, std::move(callback)); |
| 327 | event.loop(); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 328 | |
| 329 | result = shutdown(sockfd, SHUT_RDWR); |
| 330 | if (-1 == result) |
| 331 | { |
| 332 | returnCode = -errno; |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 333 | std::cerr << "Failed to shutdown the socket, RC=" << returnCode << "\n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 334 | exit(EXIT_FAILURE); |
| 335 | } |
| 336 | exit(EXIT_FAILURE); |
| 337 | } |