Manojkiran Eda | ef77305 | 2021-07-29 09:29:28 +0530 | [diff] [blame] | 1 | #include "common/flight_recorder.hpp" |
Deepak Kodihalli | d130e1a | 2020-06-17 05:55:32 -0500 | [diff] [blame] | 2 | #include "common/utils.hpp" |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 3 | #include "dbus_impl_requester.hpp" |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 4 | #include "fw-update/manager.hpp" |
Andrew Jeffery | 7c1dc7e | 2023-04-28 14:52:16 +0930 | [diff] [blame] | 5 | #include "instance_id.hpp" |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 6 | #include "invoker.hpp" |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 7 | #include "requester/handler.hpp" |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 8 | #include "requester/mctp_endpoint_discovery.hpp" |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 9 | #include "requester/request.hpp" |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 10 | |
| 11 | #include <err.h> |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 12 | #include <getopt.h> |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 13 | #include <libpldm/base.h> |
| 14 | #include <libpldm/bios.h> |
| 15 | #include <libpldm/pdr.h> |
| 16 | #include <libpldm/platform.h> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 17 | #include <poll.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <sys/socket.h> |
| 20 | #include <sys/types.h> |
| 21 | #include <sys/un.h> |
| 22 | #include <unistd.h> |
| 23 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 24 | #include <phosphor-logging/lg2.hpp> |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 25 | #include <sdeventplus/event.hpp> |
| 26 | #include <sdeventplus/source/io.hpp> |
Manojkiran Eda | ef77305 | 2021-07-29 09:29:28 +0530 | [diff] [blame] | 27 | #include <sdeventplus/source/signal.hpp> |
| 28 | #include <stdplus/signal.hpp> |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 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> |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 37 | #include <optional> |
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 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 43 | PHOSPHOR_LOG2_USING; |
| 44 | |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 45 | #ifdef LIBPLDMRESPONDER |
| 46 | #include "dbus_impl_pdr.hpp" |
| 47 | #include "host-bmc/dbus_to_event_handler.hpp" |
| 48 | #include "host-bmc/dbus_to_host_effecters.hpp" |
Tom Joseph | 20aa3e0 | 2021-08-17 04:44:19 -0700 | [diff] [blame] | 49 | #include "host-bmc/host_condition.hpp" |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 50 | #include "host-bmc/host_pdr_handler.hpp" |
| 51 | #include "libpldmresponder/base.hpp" |
| 52 | #include "libpldmresponder/bios.hpp" |
| 53 | #include "libpldmresponder/fru.hpp" |
| 54 | #include "libpldmresponder/oem_handler.hpp" |
| 55 | #include "libpldmresponder/platform.hpp" |
| 56 | #include "xyz/openbmc_project/PLDM/Event/server.hpp" |
| 57 | #endif |
| 58 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 59 | #ifdef OEM_IBM |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 60 | #include "libpldmresponder/bios_oem_ibm.hpp" |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 61 | #include "libpldmresponder/file_io.hpp" |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 62 | #include "libpldmresponder/oem_ibm_handler.hpp" |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 63 | #endif |
| 64 | |
| 65 | constexpr uint8_t MCTP_MSG_TYPE_PLDM = 1; |
| 66 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 67 | using namespace pldm; |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 68 | using namespace sdeventplus; |
| 69 | using namespace sdeventplus::source; |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 70 | using namespace pldm::responder; |
| 71 | using namespace pldm::utils; |
Manojkiran Eda | ef77305 | 2021-07-29 09:29:28 +0530 | [diff] [blame] | 72 | using sdeventplus::source::Signal; |
| 73 | using namespace pldm::flightrecorder; |
| 74 | |
| 75 | void interruptFlightRecorderCallBack(Signal& /*signal*/, |
| 76 | const struct signalfd_siginfo*) |
| 77 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 78 | error("Received SIGUR1(10) Signal interrupt"); |
Manojkiran Eda | ef77305 | 2021-07-29 09:29:28 +0530 | [diff] [blame] | 79 | // obtain the flight recorder instance and dump the recorder |
| 80 | FlightRecorder::GetInstance().playRecorder(); |
| 81 | } |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 82 | |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 83 | static std::optional<Response> |
| 84 | processRxMsg(const std::vector<uint8_t>& requestMsg, Invoker& invoker, |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 85 | requester::Handler<requester::Request>& handler, |
| 86 | fw_update::Manager* fwManager) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 87 | { |
Manojkiran Eda | 31a7844 | 2021-09-12 15:18:25 +0530 | [diff] [blame] | 88 | using type = uint8_t; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 89 | uint8_t eid = requestMsg[0]; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 90 | pldm_header_info hdrFields{}; |
| 91 | auto hdr = reinterpret_cast<const pldm_msg_hdr*>( |
| 92 | requestMsg.data() + sizeof(eid) + sizeof(type)); |
| 93 | if (PLDM_SUCCESS != unpack_pldm_header(hdr, &hdrFields)) |
| 94 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 95 | error("Empty PLDM request header"); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 96 | return std::nullopt; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 97 | } |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 98 | |
| 99 | if (PLDM_RESPONSE != hdrFields.msg_type) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 100 | { |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 101 | Response response; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 102 | auto request = reinterpret_cast<const pldm_msg*>(hdr); |
| 103 | size_t requestLen = requestMsg.size() - sizeof(struct pldm_msg_hdr) - |
| 104 | sizeof(eid) - sizeof(type); |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 105 | try |
| 106 | { |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 107 | if (hdrFields.pldm_type != PLDM_FWUP) |
| 108 | { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 109 | response = invoker.handle(hdrFields.pldm_type, |
| 110 | hdrFields.command, request, |
| 111 | requestLen); |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 112 | } |
| 113 | else |
| 114 | { |
| 115 | response = fwManager->handleRequest(eid, hdrFields.command, |
| 116 | request, requestLen); |
| 117 | } |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 118 | } |
| 119 | catch (const std::out_of_range& e) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 120 | { |
| 121 | uint8_t completion_code = PLDM_ERROR_UNSUPPORTED_PLDM_CMD; |
| 122 | response.resize(sizeof(pldm_msg_hdr)); |
| 123 | auto responseHdr = reinterpret_cast<pldm_msg_hdr*>(response.data()); |
| 124 | pldm_header_info header{}; |
| 125 | header.msg_type = PLDM_RESPONSE; |
| 126 | header.instance = hdrFields.instance; |
| 127 | header.pldm_type = hdrFields.pldm_type; |
| 128 | header.command = hdrFields.command; |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 129 | if (PLDM_SUCCESS != pack_pldm_header(&header, responseHdr)) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 130 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 131 | error("Failed adding response header"); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 132 | return std::nullopt; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 133 | } |
| 134 | response.insert(response.end(), completion_code); |
| 135 | } |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 136 | return response; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 137 | } |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 138 | else if (PLDM_RESPONSE == hdrFields.msg_type) |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 139 | { |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 140 | auto response = reinterpret_cast<const pldm_msg*>(hdr); |
| 141 | size_t responseLen = requestMsg.size() - sizeof(struct pldm_msg_hdr) - |
| 142 | sizeof(eid) - sizeof(type); |
| 143 | handler.handleResponse(eid, hdrFields.instance, hdrFields.pldm_type, |
| 144 | hdrFields.command, response, responseLen); |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 145 | } |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 146 | return std::nullopt; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 147 | } |
| 148 | |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 149 | void optionUsage(void) |
| 150 | { |
Riya Dixit | 797f338 | 2023-08-22 22:27:51 -0500 | [diff] [blame] | 151 | info("Usage: pldmd [options]"); |
| 152 | info("Options:"); |
| 153 | info(" [--verbose] - would enable verbosity"); |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 154 | } |
| 155 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 156 | int main(int argc, char** argv) |
| 157 | { |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 158 | bool verbose = false; |
Manojkiran Eda | f25145f | 2022-09-10 01:43:39 -0500 | [diff] [blame] | 159 | static struct option long_options[] = {{"verbose", no_argument, 0, 'v'}, |
| 160 | {0, 0, 0, 0}}; |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 161 | |
Manojkiran Eda | f25145f | 2022-09-10 01:43:39 -0500 | [diff] [blame] | 162 | auto argflag = getopt_long(argc, argv, "v", long_options, nullptr); |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 163 | switch (argflag) |
| 164 | { |
| 165 | case 'v': |
Manojkiran Eda | f25145f | 2022-09-10 01:43:39 -0500 | [diff] [blame] | 166 | verbose = true; |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 167 | break; |
Brad Bishop | c80f3ef | 2021-10-07 16:34:13 -0400 | [diff] [blame] | 168 | case -1: |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 169 | break; |
Brad Bishop | c80f3ef | 2021-10-07 16:34:13 -0400 | [diff] [blame] | 170 | default: |
Manojkiran Eda | f25145f | 2022-09-10 01:43:39 -0500 | [diff] [blame] | 171 | optionUsage(); |
Brad Bishop | c80f3ef | 2021-10-07 16:34:13 -0400 | [diff] [blame] | 172 | exit(EXIT_FAILURE); |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 173 | } |
| 174 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 175 | /* Create local socket. */ |
| 176 | int returnCode = 0; |
| 177 | int sockfd = socket(AF_UNIX, SOCK_SEQPACKET, 0); |
| 178 | if (-1 == sockfd) |
| 179 | { |
| 180 | returnCode = -errno; |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 181 | error("Failed to create the socket, RC= {RC}", "RC", returnCode); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 182 | exit(EXIT_FAILURE); |
| 183 | } |
Manojkiran Eda | 9fffea2 | 2021-10-27 16:03:27 +0530 | [diff] [blame] | 184 | socklen_t optlen; |
| 185 | int currentSendbuffSize; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 186 | |
Manojkiran Eda | 9fffea2 | 2021-10-27 16:03:27 +0530 | [diff] [blame] | 187 | // Get Current send buffer size |
| 188 | optlen = sizeof(currentSendbuffSize); |
| 189 | |
| 190 | int res = getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, ¤tSendbuffSize, |
| 191 | &optlen); |
| 192 | if (res == -1) |
| 193 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 194 | error("Error in obtaining the default send buffer size, Error : {ERR}", |
| 195 | "ERR", strerror(errno)); |
Manojkiran Eda | 9fffea2 | 2021-10-27 16:03:27 +0530 | [diff] [blame] | 196 | } |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 197 | auto event = Event::get_default(); |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 198 | auto& bus = pldm::utils::DBusHandler::getBus(); |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 199 | sdbusplus::server::manager_t objManager(bus, |
| 200 | "/xyz/openbmc_project/software"); |
Andrew Jeffery | 7c1dc7e | 2023-04-28 14:52:16 +0930 | [diff] [blame] | 201 | |
| 202 | InstanceIdDb instanceIdDb; |
| 203 | dbus_api::Requester dbusImplReq(bus, "/xyz/openbmc_project/pldm", |
| 204 | instanceIdDb); |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 205 | sdbusplus::server::manager::manager inventoryManager( |
| 206 | bus, "/xyz/openbmc_project/inventory"); |
Pavithra Barithaya | 319ebb3 | 2021-05-06 06:09:11 -0500 | [diff] [blame] | 207 | |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 208 | Invoker invoker{}; |
Manojkiran Eda | 9fffea2 | 2021-10-27 16:03:27 +0530 | [diff] [blame] | 209 | requester::Handler<requester::Request> reqHandler( |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 210 | sockfd, event, instanceIdDb, currentSendbuffSize, verbose); |
Manojkiran Eda | 9fffea2 | 2021-10-27 16:03:27 +0530 | [diff] [blame] | 211 | |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 212 | #ifdef LIBPLDMRESPONDER |
| 213 | using namespace pldm::state_sensor; |
Tom Joseph | 20aa3e0 | 2021-08-17 04:44:19 -0700 | [diff] [blame] | 214 | dbus_api::Host dbusImplHost(bus, "/xyz/openbmc_project/pldm"); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 215 | std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)> pdrRepo( |
| 216 | pldm_pdr_init(), pldm_pdr_destroy); |
Andrew Jeffery | acb2029 | 2023-06-30 11:47:44 +0930 | [diff] [blame] | 217 | if (!pdrRepo) |
| 218 | { |
| 219 | throw std::runtime_error("Failed to instantiate PDR repository"); |
| 220 | } |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 221 | std::unique_ptr<pldm_entity_association_tree, |
| 222 | decltype(&pldm_entity_association_tree_destroy)> |
| 223 | entityTree(pldm_entity_association_tree_init(), |
| 224 | pldm_entity_association_tree_destroy); |
Andrew Jeffery | abcd6ca | 2023-06-30 13:53:35 +0930 | [diff] [blame] | 225 | if (!entityTree) |
| 226 | { |
| 227 | throw std::runtime_error( |
| 228 | "Failed to instantiate general PDR entity association tree"); |
| 229 | } |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 230 | std::unique_ptr<pldm_entity_association_tree, |
| 231 | decltype(&pldm_entity_association_tree_destroy)> |
| 232 | bmcEntityTree(pldm_entity_association_tree_init(), |
| 233 | pldm_entity_association_tree_destroy); |
Andrew Jeffery | abcd6ca | 2023-06-30 13:53:35 +0930 | [diff] [blame] | 234 | if (!bmcEntityTree) |
| 235 | { |
| 236 | throw std::runtime_error( |
| 237 | "Failed to instantiate BMC PDR entity association tree"); |
| 238 | } |
Pavithra Barithaya | 319ebb3 | 2021-05-06 06:09:11 -0500 | [diff] [blame] | 239 | std::shared_ptr<HostPDRHandler> hostPDRHandler; |
Sampa Misra | c0c6054 | 2020-07-01 02:34:25 -0500 | [diff] [blame] | 240 | std::unique_ptr<pldm::host_effecters::HostEffecterParser> |
| 241 | hostEffecterParser; |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 242 | std::unique_ptr<DbusToPLDMEvent> dbusToPLDMEventHandler; |
Brad Bishop | fc0d14d | 2021-10-12 19:34:20 -0400 | [diff] [blame] | 243 | DBusHandler dbusHandler; |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 244 | auto hostEID = pldm::utils::readHostEID(); |
| 245 | if (hostEID) |
| 246 | { |
Pavithra Barithaya | 319ebb3 | 2021-05-06 06:09:11 -0500 | [diff] [blame] | 247 | hostPDRHandler = std::make_shared<HostPDRHandler>( |
Pavithra Barithaya | 3aec997 | 2020-12-14 01:55:44 -0600 | [diff] [blame] | 248 | sockfd, hostEID, event, pdrRepo.get(), EVENTS_JSONS_DIR, |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 249 | entityTree.get(), bmcEntityTree.get(), instanceIdDb, &reqHandler); |
Pavithra Barithaya | 319ebb3 | 2021-05-06 06:09:11 -0500 | [diff] [blame] | 250 | // HostFirmware interface needs access to hostPDR to know if host |
| 251 | // is running |
| 252 | dbusImplHost.setHostPdrObj(hostPDRHandler); |
| 253 | |
Sampa Misra | c0c6054 | 2020-07-01 02:34:25 -0500 | [diff] [blame] | 254 | hostEffecterParser = |
| 255 | std::make_unique<pldm::host_effecters::HostEffecterParser>( |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 256 | &instanceIdDb, sockfd, pdrRepo.get(), &dbusHandler, |
Tom Joseph | e5268cd | 2021-09-07 13:04:03 +0530 | [diff] [blame] | 257 | HOST_JSONS_DIR, &reqHandler); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 258 | dbusToPLDMEventHandler = std::make_unique<DbusToPLDMEvent>( |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 259 | sockfd, hostEID, instanceIdDb, &reqHandler); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 260 | } |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 261 | std::unique_ptr<oem_platform::Handler> oemPlatformHandler{}; |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 262 | std::unique_ptr<oem_bios::Handler> oemBiosHandler{}; |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 263 | |
| 264 | #ifdef OEM_IBM |
| 265 | std::unique_ptr<pldm::responder::CodeUpdate> codeUpdate = |
Brad Bishop | fc0d14d | 2021-10-12 19:34:20 -0400 | [diff] [blame] | 266 | std::make_unique<pldm::responder::CodeUpdate>(&dbusHandler); |
Varsha Kaverappa | 3ca29df | 2020-09-27 12:39:22 -0500 | [diff] [blame] | 267 | codeUpdate->clearDirPath(LID_STAGING_DIR); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 268 | oemPlatformHandler = std::make_unique<oem_ibm_platform::Handler>( |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 269 | &dbusHandler, codeUpdate.get(), sockfd, hostEID, instanceIdDb, event, |
Brad Bishop | fc0d14d | 2021-10-12 19:34:20 -0400 | [diff] [blame] | 270 | &reqHandler); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 271 | codeUpdate->setOemPlatformHandler(oemPlatformHandler.get()); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 272 | invoker.registerHandler(PLDM_OEM, std::make_unique<oem_ibm::Handler>( |
| 273 | oemPlatformHandler.get(), sockfd, |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 274 | hostEID, &instanceIdDb, &reqHandler)); |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 275 | oemBiosHandler = std::make_unique<oem::ibm::bios::Handler>(&dbusHandler); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 276 | #endif |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 277 | |
| 278 | auto biosHandler = std::make_unique<bios::Handler>( |
| 279 | sockfd, hostEID, &instanceIdDb, &reqHandler, oemBiosHandler.get()); |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 280 | auto fruHandler = std::make_unique<fru::Handler>( |
Manojkiran Eda | 03b01ca | 2021-06-29 08:55:09 +0530 | [diff] [blame] | 281 | FRU_JSONS_DIR, FRU_MASTER_JSON, pdrRepo.get(), entityTree.get(), |
| 282 | bmcEntityTree.get()); |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 283 | // FRU table is built lazily when a FRU command or Get PDR command is |
| 284 | // handled. To enable building FRU table, the FRU handler is passed to the |
| 285 | // Platform handler. |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 286 | auto platformHandler = std::make_unique<platform::Handler>( |
Brad Bishop | fc0d14d | 2021-10-12 19:34:20 -0400 | [diff] [blame] | 287 | &dbusHandler, PDR_JSONS_DIR, pdrRepo.get(), hostPDRHandler.get(), |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 288 | dbusToPLDMEventHandler.get(), fruHandler.get(), |
Sampa Misra | 5fb37d5 | 2021-03-06 07:26:00 -0600 | [diff] [blame] | 289 | oemPlatformHandler.get(), event, true); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 290 | #ifdef OEM_IBM |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 291 | pldm::responder::oem_ibm_platform::Handler* oemIbmPlatformHandler = |
| 292 | dynamic_cast<pldm::responder::oem_ibm_platform::Handler*>( |
| 293 | oemPlatformHandler.get()); |
| 294 | oemIbmPlatformHandler->setPlatformHandler(platformHandler.get()); |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 295 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 296 | #endif |
| 297 | |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 298 | invoker.registerHandler(PLDM_BIOS, std::move(biosHandler)); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 299 | invoker.registerHandler(PLDM_PLATFORM, std::move(platformHandler)); |
Sagar Srinivas | 79669c9 | 2021-04-28 15:43:30 -0500 | [diff] [blame] | 300 | invoker.registerHandler( |
| 301 | PLDM_BASE, |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 302 | std::make_unique<base::Handler>(hostEID, instanceIdDb, event, |
Sagar Srinivas | 79669c9 | 2021-04-28 15:43:30 -0500 | [diff] [blame] | 303 | oemPlatformHandler.get(), &reqHandler)); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 304 | invoker.registerHandler(PLDM_FRU, std::move(fruHandler)); |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 305 | dbus_api::Pdr dbusImplPdr(bus, "/xyz/openbmc_project/pldm", pdrRepo.get()); |
| 306 | sdbusplus::xyz::openbmc_project::PLDM::server::Event dbusImplEvent( |
| 307 | bus, "/xyz/openbmc_project/pldm"); |
Tom Joseph | 20aa3e0 | 2021-08-17 04:44:19 -0700 | [diff] [blame] | 308 | |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 309 | #endif |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 310 | |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 311 | pldm::utils::CustomFD socketFd(sockfd); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 312 | |
| 313 | struct sockaddr_un addr |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 314 | {}; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 315 | addr.sun_family = AF_UNIX; |
| 316 | const char path[] = "\0mctp-mux"; |
| 317 | memcpy(addr.sun_path, path, sizeof(path) - 1); |
| 318 | int result = connect(socketFd(), reinterpret_cast<struct sockaddr*>(&addr), |
| 319 | sizeof(path) + sizeof(addr.sun_family) - 1); |
| 320 | if (-1 == result) |
| 321 | { |
| 322 | returnCode = -errno; |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 323 | error("Failed to connect to the socket, RC= {RC}", "RC", returnCode); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 324 | exit(EXIT_FAILURE); |
| 325 | } |
| 326 | |
| 327 | result = write(socketFd(), &MCTP_MSG_TYPE_PLDM, sizeof(MCTP_MSG_TYPE_PLDM)); |
| 328 | if (-1 == result) |
| 329 | { |
| 330 | returnCode = -errno; |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 331 | error("Failed to send message type as pldm to mctp, RC= {RC}", "RC", |
| 332 | returnCode); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 333 | exit(EXIT_FAILURE); |
| 334 | } |
| 335 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 336 | std::unique_ptr<fw_update::Manager> fwManager = |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 337 | std::make_unique<fw_update::Manager>(event, reqHandler, instanceIdDb); |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 338 | std::unique_ptr<MctpDiscovery> mctpDiscoveryHandler = |
| 339 | std::make_unique<MctpDiscovery>(bus, fwManager.get()); |
| 340 | |
Manojkiran Eda | 9fffea2 | 2021-10-27 16:03:27 +0530 | [diff] [blame] | 341 | auto callback = [verbose, &invoker, &reqHandler, currentSendbuffSize, |
| 342 | &fwManager](IO& io, int fd, uint32_t revents) mutable { |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 343 | if (!(revents & EPOLLIN)) |
| 344 | { |
| 345 | return; |
| 346 | } |
| 347 | |
| 348 | // Outgoing message. |
| 349 | struct iovec iov[2]{}; |
| 350 | |
| 351 | // This structure contains the parameter information for the response |
| 352 | // message. |
| 353 | struct msghdr msg |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 354 | {}; |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 355 | |
| 356 | int returnCode = 0; |
| 357 | ssize_t peekedLength = recv(fd, nullptr, 0, MSG_PEEK | MSG_TRUNC); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 358 | if (0 == peekedLength) |
| 359 | { |
Deepak Kodihalli | 23c5204 | 2020-09-01 03:04:32 -0500 | [diff] [blame] | 360 | // MCTP daemon has closed the socket this daemon is connected to. |
| 361 | // This may or may not be an error scenario, in either case the |
| 362 | // recovery mechanism for this daemon is to restart, and hence exit |
| 363 | // the event loop, that will cause this daemon to exit with a |
| 364 | // failure code. |
| 365 | io.get_event().exit(0); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 366 | } |
| 367 | else if (peekedLength <= -1) |
| 368 | { |
| 369 | returnCode = -errno; |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 370 | error("recv system call failed, RC= {RC}", "RC", returnCode); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 371 | } |
| 372 | else |
| 373 | { |
| 374 | std::vector<uint8_t> requestMsg(peekedLength); |
| 375 | auto recvDataLength = recv( |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 376 | fd, static_cast<void*>(requestMsg.data()), peekedLength, 0); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 377 | if (recvDataLength == peekedLength) |
| 378 | { |
Manojkiran Eda | ef77305 | 2021-07-29 09:29:28 +0530 | [diff] [blame] | 379 | FlightRecorder::GetInstance().saveRecord(requestMsg, false); |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 380 | if (verbose) |
| 381 | { |
Tom Joseph | e5268cd | 2021-09-07 13:04:03 +0530 | [diff] [blame] | 382 | printBuffer(Rx, requestMsg); |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 383 | } |
Tom Joseph | e5268cd | 2021-09-07 13:04:03 +0530 | [diff] [blame] | 384 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 385 | if (MCTP_MSG_TYPE_PLDM != requestMsg[1]) |
| 386 | { |
| 387 | // Skip this message and continue. |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 388 | } |
| 389 | else |
| 390 | { |
| 391 | // process message and send response |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 392 | auto response = processRxMsg(requestMsg, invoker, |
| 393 | reqHandler, fwManager.get()); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 394 | if (response.has_value()) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 395 | { |
Manojkiran Eda | ef77305 | 2021-07-29 09:29:28 +0530 | [diff] [blame] | 396 | FlightRecorder::GetInstance().saveRecord(*response, |
| 397 | true); |
Deepak Kodihalli | 8ffbbe0 | 2019-08-14 06:51:38 -0500 | [diff] [blame] | 398 | if (verbose) |
| 399 | { |
Tom Joseph | e5268cd | 2021-09-07 13:04:03 +0530 | [diff] [blame] | 400 | printBuffer(Tx, *response); |
Deepak Kodihalli | 8ffbbe0 | 2019-08-14 06:51:38 -0500 | [diff] [blame] | 401 | } |
| 402 | |
Zahed Hossain | 09a96e0 | 2019-08-06 07:42:37 -0500 | [diff] [blame] | 403 | iov[0].iov_base = &requestMsg[0]; |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 404 | iov[0].iov_len = sizeof(requestMsg[0]) + |
| 405 | sizeof(requestMsg[1]); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 406 | iov[1].iov_base = (*response).data(); |
| 407 | iov[1].iov_len = (*response).size(); |
Zahed Hossain | 09a96e0 | 2019-08-06 07:42:37 -0500 | [diff] [blame] | 408 | |
| 409 | msg.msg_iov = iov; |
| 410 | msg.msg_iovlen = sizeof(iov) / sizeof(iov[0]); |
Manojkiran Eda | 9fffea2 | 2021-10-27 16:03:27 +0530 | [diff] [blame] | 411 | if (currentSendbuffSize >= 0 && |
| 412 | (size_t)currentSendbuffSize < (*response).size()) |
| 413 | { |
| 414 | int oldBuffSize = currentSendbuffSize; |
| 415 | currentSendbuffSize = (*response).size(); |
| 416 | int res = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, |
| 417 | ¤tSendbuffSize, |
| 418 | sizeof(currentSendbuffSize)); |
| 419 | if (res == -1) |
| 420 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 421 | error( |
| 422 | "Responder : Failed to set the new send buffer size [bytes] : {CURR_SND_BUF_SIZE}", |
| 423 | "CURR_SND_BUF_SIZE", currentSendbuffSize); |
| 424 | error( |
| 425 | "from current size [bytes] : {OLD_BUF_SIZE}, Error : {ERR}", |
| 426 | "OLD_BUF_SIZE", oldBuffSize, "ERR", |
| 427 | strerror(errno)); |
Manojkiran Eda | 9fffea2 | 2021-10-27 16:03:27 +0530 | [diff] [blame] | 428 | return; |
| 429 | } |
| 430 | } |
Zahed Hossain | 09a96e0 | 2019-08-06 07:42:37 -0500 | [diff] [blame] | 431 | |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 432 | int result = sendmsg(fd, &msg, 0); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 433 | if (-1 == result) |
| 434 | { |
| 435 | returnCode = -errno; |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 436 | error("sendto system call failed, RC= {RC}", "RC", |
| 437 | returnCode); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 438 | } |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | else |
| 443 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 444 | error( |
| 445 | "Failure to read peeked length packet. peekedLength = {PEEK_LEN}, recvDataLength= {RECV_LEN}", |
| 446 | "PEEK_LEN", peekedLength, "RECV_LEN", recvDataLength); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 447 | } |
| 448 | } |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 449 | }; |
| 450 | |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 451 | bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); |
| 452 | bus.request_name("xyz.openbmc_project.PLDM"); |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 453 | IO io(event, socketFd(), EPOLLIN, std::move(callback)); |
Manojkiran Eda | 88bc718 | 2021-09-08 18:37:30 +0530 | [diff] [blame] | 454 | #ifdef LIBPLDMRESPONDER |
| 455 | if (hostPDRHandler) |
| 456 | { |
| 457 | hostPDRHandler->setHostFirmwareCondition(); |
| 458 | } |
| 459 | #endif |
Manojkiran Eda | ef77305 | 2021-07-29 09:29:28 +0530 | [diff] [blame] | 460 | stdplus::signal::block(SIGUSR1); |
| 461 | sdeventplus::source::Signal sigUsr1( |
| 462 | event, SIGUSR1, std::bind_front(&interruptFlightRecorderCallBack)); |
Brad Bishop | 3a22b97 | 2021-10-07 17:01:58 -0400 | [diff] [blame] | 463 | returnCode = event.loop(); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 464 | |
Brad Bishop | 3a22b97 | 2021-10-07 17:01:58 -0400 | [diff] [blame] | 465 | if (shutdown(sockfd, SHUT_RDWR)) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 466 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 467 | error("Failed to shutdown the socket"); |
Brad Bishop | 3a22b97 | 2021-10-07 17:01:58 -0400 | [diff] [blame] | 468 | } |
| 469 | if (returnCode) |
| 470 | { |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 471 | exit(EXIT_FAILURE); |
| 472 | } |
Brad Bishop | 3a22b97 | 2021-10-07 17:01:58 -0400 | [diff] [blame] | 473 | |
| 474 | exit(EXIT_SUCCESS); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 475 | } |