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