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