Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 1 | |
Manojkiran Eda | ef77305 | 2021-07-29 09:29:28 +0530 | [diff] [blame] | 2 | #include "common/flight_recorder.hpp" |
Andrew Jeffery | 2abbce7 | 2023-10-18 10:17:35 +1030 | [diff] [blame] | 3 | #include "common/instance_id.hpp" |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 4 | #include "common/transport.hpp" |
Deepak Kodihalli | d130e1a | 2020-06-17 05:55:32 -0500 | [diff] [blame] | 5 | #include "common/utils.hpp" |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 6 | #include "dbus_impl_requester.hpp" |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 7 | #include "fw-update/manager.hpp" |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 8 | #include "invoker.hpp" |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 9 | #include "requester/handler.hpp" |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 10 | #include "requester/mctp_endpoint_discovery.hpp" |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 11 | #include "requester/request.hpp" |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 12 | |
| 13 | #include <err.h> |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 14 | #include <getopt.h> |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 15 | #include <libpldm/base.h> |
| 16 | #include <libpldm/bios.h> |
| 17 | #include <libpldm/pdr.h> |
| 18 | #include <libpldm/platform.h> |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 19 | #include <libpldm/transport.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 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 27 | #include <phosphor-logging/lg2.hpp> |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 28 | #include <sdeventplus/event.hpp> |
| 29 | #include <sdeventplus/source/io.hpp> |
Manojkiran Eda | ef77305 | 2021-07-29 09:29:28 +0530 | [diff] [blame] | 30 | #include <sdeventplus/source/signal.hpp> |
| 31 | #include <stdplus/signal.hpp> |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 32 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 33 | #include <cstdio> |
| 34 | #include <cstring> |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 35 | #include <fstream> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 36 | #include <iomanip> |
| 37 | #include <iterator> |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 38 | #include <memory> |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 39 | #include <ranges> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 40 | #include <sstream> |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 41 | #include <stdexcept> |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 42 | #include <string> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 43 | #include <vector> |
| 44 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 45 | PHOSPHOR_LOG2_USING; |
| 46 | |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 47 | #ifdef LIBPLDMRESPONDER |
| 48 | #include "dbus_impl_pdr.hpp" |
| 49 | #include "host-bmc/dbus_to_event_handler.hpp" |
| 50 | #include "host-bmc/dbus_to_host_effecters.hpp" |
Tom Joseph | 20aa3e0 | 2021-08-17 04:44:19 -0700 | [diff] [blame] | 51 | #include "host-bmc/host_condition.hpp" |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 52 | #include "host-bmc/host_pdr_handler.hpp" |
| 53 | #include "libpldmresponder/base.hpp" |
| 54 | #include "libpldmresponder/bios.hpp" |
| 55 | #include "libpldmresponder/fru.hpp" |
| 56 | #include "libpldmresponder/oem_handler.hpp" |
| 57 | #include "libpldmresponder/platform.hpp" |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 58 | #include "libpldmresponder/platform_config.hpp" |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 59 | #include "xyz/openbmc_project/PLDM/Event/server.hpp" |
| 60 | #endif |
| 61 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 62 | #ifdef OEM_IBM |
| 63 | #include "libpldmresponder/file_io.hpp" |
Pavithra Barithaya | a410c65 | 2021-07-22 01:32:47 -0500 | [diff] [blame] | 64 | #include "libpldmresponder/fru_oem_ibm.hpp" |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 65 | #include "libpldmresponder/oem_ibm_handler.hpp" |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 66 | #endif |
| 67 | |
| 68 | constexpr uint8_t MCTP_MSG_TYPE_PLDM = 1; |
| 69 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 70 | using namespace pldm; |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 71 | using namespace sdeventplus; |
| 72 | using namespace sdeventplus::source; |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 73 | using namespace pldm::responder; |
| 74 | using namespace pldm::utils; |
Manojkiran Eda | ef77305 | 2021-07-29 09:29:28 +0530 | [diff] [blame] | 75 | using sdeventplus::source::Signal; |
| 76 | using namespace pldm::flightrecorder; |
| 77 | |
| 78 | void interruptFlightRecorderCallBack(Signal& /*signal*/, |
| 79 | const struct signalfd_siginfo*) |
| 80 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 81 | error("Received SIGUR1(10) Signal interrupt"); |
Manojkiran Eda | ef77305 | 2021-07-29 09:29:28 +0530 | [diff] [blame] | 82 | // obtain the flight recorder instance and dump the recorder |
| 83 | FlightRecorder::GetInstance().playRecorder(); |
| 84 | } |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 85 | |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 86 | static std::optional<Response> |
| 87 | processRxMsg(const std::vector<uint8_t>& requestMsg, Invoker& invoker, |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 88 | requester::Handler<requester::Request>& handler, |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 89 | fw_update::Manager* fwManager, pldm_tid_t tid) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 90 | { |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 91 | uint8_t eid = tid; |
| 92 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 93 | pldm_header_info hdrFields{}; |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 94 | auto hdr = reinterpret_cast<const pldm_msg_hdr*>(requestMsg.data()); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 95 | if (PLDM_SUCCESS != unpack_pldm_header(hdr, &hdrFields)) |
| 96 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 97 | error("Empty PLDM request header"); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 98 | return std::nullopt; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 99 | } |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 100 | |
| 101 | if (PLDM_RESPONSE != hdrFields.msg_type) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 102 | { |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 103 | Response response; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 104 | auto request = reinterpret_cast<const pldm_msg*>(hdr); |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 105 | size_t requestLen = requestMsg.size() - sizeof(struct pldm_msg_hdr); |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 106 | try |
| 107 | { |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 108 | if (hdrFields.pldm_type != PLDM_FWUP) |
| 109 | { |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 110 | response = invoker.handle(tid, hdrFields.pldm_type, |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 111 | hdrFields.command, request, |
| 112 | requestLen); |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 113 | } |
| 114 | else |
| 115 | { |
| 116 | response = fwManager->handleRequest(eid, hdrFields.command, |
| 117 | request, requestLen); |
| 118 | } |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 119 | } |
| 120 | catch (const std::out_of_range& e) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 121 | { |
| 122 | uint8_t completion_code = PLDM_ERROR_UNSUPPORTED_PLDM_CMD; |
| 123 | response.resize(sizeof(pldm_msg_hdr)); |
| 124 | auto responseHdr = reinterpret_cast<pldm_msg_hdr*>(response.data()); |
| 125 | pldm_header_info header{}; |
| 126 | header.msg_type = PLDM_RESPONSE; |
| 127 | header.instance = hdrFields.instance; |
| 128 | header.pldm_type = hdrFields.pldm_type; |
| 129 | header.command = hdrFields.command; |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 130 | if (PLDM_SUCCESS != pack_pldm_header(&header, responseHdr)) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 131 | { |
Kamalkumar Patel | 58cbcaf | 2023-10-06 03:48:25 -0500 | [diff] [blame] | 132 | error("Failed adding response header: {ERROR}", "ERROR", e); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 133 | return std::nullopt; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 134 | } |
| 135 | response.insert(response.end(), completion_code); |
| 136 | } |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 137 | return response; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 138 | } |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 139 | else if (PLDM_RESPONSE == hdrFields.msg_type) |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 140 | { |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 141 | auto response = reinterpret_cast<const pldm_msg*>(hdr); |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 142 | size_t responseLen = requestMsg.size() - sizeof(struct pldm_msg_hdr); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 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 | } |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 174 | // Setup PLDM requester transport |
| 175 | auto hostEID = pldm::utils::readHostEID(); |
| 176 | /* To maintain current behaviour until we have the infrastructure to find |
| 177 | * and use the correct TIDs */ |
| 178 | pldm_tid_t TID = hostEID; |
| 179 | PldmTransport pldmTransport{}; |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 180 | auto event = Event::get_default(); |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 181 | auto& bus = pldm::utils::DBusHandler::getBus(); |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 182 | sdbusplus::server::manager_t objManager(bus, |
| 183 | "/xyz/openbmc_project/software"); |
Andrew Jeffery | 7c1dc7e | 2023-04-28 14:52:16 +0930 | [diff] [blame] | 184 | |
| 185 | InstanceIdDb instanceIdDb; |
| 186 | dbus_api::Requester dbusImplReq(bus, "/xyz/openbmc_project/pldm", |
| 187 | instanceIdDb); |
Patrick Williams | 705fa98 | 2023-09-27 02:32:20 -0500 | [diff] [blame] | 188 | sdbusplus::server::manager_t inventoryManager( |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 189 | bus, "/xyz/openbmc_project/inventory"); |
Pavithra Barithaya | 319ebb3 | 2021-05-06 06:09:11 -0500 | [diff] [blame] | 190 | |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 191 | Invoker invoker{}; |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 192 | requester::Handler<requester::Request> reqHandler(&pldmTransport, event, |
| 193 | instanceIdDb, verbose); |
Manojkiran Eda | 9fffea2 | 2021-10-27 16:03:27 +0530 | [diff] [blame] | 194 | |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 195 | #ifdef LIBPLDMRESPONDER |
| 196 | using namespace pldm::state_sensor; |
Tom Joseph | 20aa3e0 | 2021-08-17 04:44:19 -0700 | [diff] [blame] | 197 | dbus_api::Host dbusImplHost(bus, "/xyz/openbmc_project/pldm"); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 198 | std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)> pdrRepo( |
| 199 | pldm_pdr_init(), pldm_pdr_destroy); |
Andrew Jeffery | acb2029 | 2023-06-30 11:47:44 +0930 | [diff] [blame] | 200 | if (!pdrRepo) |
| 201 | { |
| 202 | throw std::runtime_error("Failed to instantiate PDR repository"); |
| 203 | } |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 204 | std::unique_ptr<pldm_entity_association_tree, |
| 205 | decltype(&pldm_entity_association_tree_destroy)> |
| 206 | entityTree(pldm_entity_association_tree_init(), |
| 207 | pldm_entity_association_tree_destroy); |
Andrew Jeffery | abcd6ca | 2023-06-30 13:53:35 +0930 | [diff] [blame] | 208 | if (!entityTree) |
| 209 | { |
| 210 | throw std::runtime_error( |
| 211 | "Failed to instantiate general PDR entity association tree"); |
| 212 | } |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 213 | std::unique_ptr<pldm_entity_association_tree, |
| 214 | decltype(&pldm_entity_association_tree_destroy)> |
| 215 | bmcEntityTree(pldm_entity_association_tree_init(), |
| 216 | pldm_entity_association_tree_destroy); |
Andrew Jeffery | abcd6ca | 2023-06-30 13:53:35 +0930 | [diff] [blame] | 217 | if (!bmcEntityTree) |
| 218 | { |
| 219 | throw std::runtime_error( |
| 220 | "Failed to instantiate BMC PDR entity association tree"); |
| 221 | } |
Pavithra Barithaya | 319ebb3 | 2021-05-06 06:09:11 -0500 | [diff] [blame] | 222 | std::shared_ptr<HostPDRHandler> hostPDRHandler; |
Sampa Misra | c0c6054 | 2020-07-01 02:34:25 -0500 | [diff] [blame] | 223 | std::unique_ptr<pldm::host_effecters::HostEffecterParser> |
| 224 | hostEffecterParser; |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 225 | std::unique_ptr<DbusToPLDMEvent> dbusToPLDMEventHandler; |
Brad Bishop | fc0d14d | 2021-10-12 19:34:20 -0400 | [diff] [blame] | 226 | DBusHandler dbusHandler; |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 227 | std::unique_ptr<oem_platform::Handler> oemPlatformHandler{}; |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 228 | std::unique_ptr<platform_config::Handler> platformConfigHandler{}; |
| 229 | platformConfigHandler = std::make_unique<platform_config::Handler>(); |
Pavithra Barithaya | a410c65 | 2021-07-22 01:32:47 -0500 | [diff] [blame] | 230 | std::unique_ptr<oem_fru::Handler> oemFruHandler{}; |
| 231 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 232 | #ifdef OEM_IBM |
| 233 | std::unique_ptr<pldm::responder::CodeUpdate> codeUpdate = |
Brad Bishop | fc0d14d | 2021-10-12 19:34:20 -0400 | [diff] [blame] | 234 | std::make_unique<pldm::responder::CodeUpdate>(&dbusHandler); |
Varsha Kaverappa | 3ca29df | 2020-09-27 12:39:22 -0500 | [diff] [blame] | 235 | codeUpdate->clearDirPath(LID_STAGING_DIR); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 236 | oemPlatformHandler = std::make_unique<oem_ibm_platform::Handler>( |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 237 | &dbusHandler, codeUpdate.get(), pldmTransport.getEventSource(), hostEID, |
| 238 | instanceIdDb, event, &reqHandler); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 239 | codeUpdate->setOemPlatformHandler(oemPlatformHandler.get()); |
Pavithra Barithaya | a410c65 | 2021-07-22 01:32:47 -0500 | [diff] [blame] | 240 | oemFruHandler = std::make_unique<oem_ibm_fru::Handler>(pdrRepo.get()); |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 241 | invoker.registerHandler(PLDM_OEM, std::make_unique<oem_ibm::Handler>( |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 242 | oemPlatformHandler.get(), |
| 243 | pldmTransport.getEventSource(), |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 244 | hostEID, &instanceIdDb, &reqHandler)); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 245 | #endif |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 246 | if (hostEID) |
| 247 | { |
| 248 | hostPDRHandler = std::make_shared<HostPDRHandler>( |
| 249 | pldmTransport.getEventSource(), hostEID, event, pdrRepo.get(), |
| 250 | EVENTS_JSONS_DIR, entityTree.get(), bmcEntityTree.get(), |
| 251 | instanceIdDb, &reqHandler, oemPlatformHandler.get()); |
| 252 | // HostFirmware interface needs access to hostPDR to know if host |
| 253 | // is running |
| 254 | dbusImplHost.setHostPdrObj(hostPDRHandler); |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 255 | |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 256 | hostEffecterParser = |
| 257 | std::make_unique<pldm::host_effecters::HostEffecterParser>( |
| 258 | &instanceIdDb, pldmTransport.getEventSource(), pdrRepo.get(), |
| 259 | &dbusHandler, HOST_JSONS_DIR, &reqHandler); |
| 260 | dbusToPLDMEventHandler = std::make_unique<DbusToPLDMEvent>( |
| 261 | pldmTransport.getEventSource(), hostEID, instanceIdDb, &reqHandler); |
| 262 | } |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 263 | auto biosHandler = std::make_unique<bios::Handler>( |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 264 | pldmTransport.getEventSource(), hostEID, &instanceIdDb, &reqHandler, |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 265 | platformConfigHandler.get()); |
Pavithra Barithaya | a410c65 | 2021-07-22 01:32:47 -0500 | [diff] [blame] | 266 | |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 267 | auto fruHandler = std::make_unique<fru::Handler>( |
Manojkiran Eda | 03b01ca | 2021-06-29 08:55:09 +0530 | [diff] [blame] | 268 | FRU_JSONS_DIR, FRU_MASTER_JSON, pdrRepo.get(), entityTree.get(), |
Pavithra Barithaya | a410c65 | 2021-07-22 01:32:47 -0500 | [diff] [blame] | 269 | bmcEntityTree.get(), oemFruHandler.get()); |
| 270 | |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 271 | // FRU table is built lazily when a FRU command or Get PDR command is |
| 272 | // handled. To enable building FRU table, the FRU handler is passed to the |
| 273 | // Platform handler. |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 274 | auto platformHandler = std::make_unique<platform::Handler>( |
Sagar Srinivas | 90314a3 | 2023-10-17 10:38:03 -0500 | [diff] [blame] | 275 | &dbusHandler, hostEID, &instanceIdDb, PDR_JSONS_DIR, pdrRepo.get(), |
| 276 | hostPDRHandler.get(), dbusToPLDMEventHandler.get(), fruHandler.get(), |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 277 | oemPlatformHandler.get(), platformConfigHandler.get(), &reqHandler, |
| 278 | event, true); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 279 | #ifdef OEM_IBM |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 280 | pldm::responder::oem_ibm_platform::Handler* oemIbmPlatformHandler = |
| 281 | dynamic_cast<pldm::responder::oem_ibm_platform::Handler*>( |
| 282 | oemPlatformHandler.get()); |
| 283 | oemIbmPlatformHandler->setPlatformHandler(platformHandler.get()); |
Pavithra Barithaya | a410c65 | 2021-07-22 01:32:47 -0500 | [diff] [blame] | 284 | |
| 285 | pldm::responder::oem_ibm_fru::Handler* oemIbmFruHandler = |
| 286 | dynamic_cast<pldm::responder::oem_ibm_fru::Handler*>( |
| 287 | oemFruHandler.get()); |
| 288 | oemIbmFruHandler->setIBMFruHandler(fruHandler.get()); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 289 | #endif |
| 290 | |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 291 | invoker.registerHandler(PLDM_BIOS, std::move(biosHandler)); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 292 | invoker.registerHandler(PLDM_PLATFORM, std::move(platformHandler)); |
Sagar Srinivas | 90314a3 | 2023-10-17 10:38:03 -0500 | [diff] [blame] | 293 | invoker.registerHandler(PLDM_BASE, std::make_unique<base::Handler>( |
| 294 | event, oemPlatformHandler.get())); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 295 | invoker.registerHandler(PLDM_FRU, std::move(fruHandler)); |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 296 | dbus_api::Pdr dbusImplPdr(bus, "/xyz/openbmc_project/pldm", pdrRepo.get()); |
| 297 | sdbusplus::xyz::openbmc_project::PLDM::server::Event dbusImplEvent( |
| 298 | bus, "/xyz/openbmc_project/pldm"); |
Tom Joseph | 20aa3e0 | 2021-08-17 04:44:19 -0700 | [diff] [blame] | 299 | |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 300 | #endif |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 301 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 302 | std::unique_ptr<fw_update::Manager> fwManager = |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 303 | std::make_unique<fw_update::Manager>(event, reqHandler, instanceIdDb); |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 304 | std::unique_ptr<MctpDiscovery> mctpDiscoveryHandler = |
| 305 | std::make_unique<MctpDiscovery>(bus, fwManager.get()); |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 306 | auto callback = [verbose, &invoker, &reqHandler, &fwManager, &pldmTransport, |
| 307 | TID](IO& io, int fd, uint32_t revents) mutable { |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 308 | if (!(revents & EPOLLIN)) |
| 309 | { |
| 310 | return; |
| 311 | } |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 312 | if (fd < 0) |
| 313 | { |
| 314 | return; |
| 315 | } |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 316 | |
| 317 | int returnCode = 0; |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 318 | void* requestMsg; |
| 319 | size_t recvDataLength; |
| 320 | returnCode = pldmTransport.recvMsg(TID, requestMsg, recvDataLength); |
| 321 | |
| 322 | if (returnCode == PLDM_REQUESTER_SUCCESS) |
| 323 | { |
| 324 | std::vector<uint8_t> requestMsgVec( |
| 325 | static_cast<uint8_t*>(requestMsg), |
| 326 | static_cast<uint8_t*>(requestMsg) + recvDataLength); |
| 327 | FlightRecorder::GetInstance().saveRecord(requestMsgVec, false); |
| 328 | if (verbose) |
| 329 | { |
| 330 | printBuffer(Rx, requestMsgVec); |
| 331 | } |
| 332 | // process message and send response |
| 333 | auto response = processRxMsg(requestMsgVec, invoker, reqHandler, |
| 334 | fwManager.get(), TID); |
| 335 | if (response.has_value()) |
| 336 | { |
| 337 | FlightRecorder::GetInstance().saveRecord(*response, true); |
| 338 | if (verbose) |
| 339 | { |
| 340 | printBuffer(Tx, *response); |
| 341 | } |
| 342 | |
| 343 | returnCode = pldmTransport.sendMsg(TID, (*response).data(), |
| 344 | (*response).size()); |
| 345 | if (returnCode != PLDM_REQUESTER_SUCCESS) |
| 346 | { |
| 347 | warning("Failed to send PLDM response: {RETURN_CODE}", |
| 348 | "RETURN_CODE", returnCode); |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | // TODO check that we get here if mctp-demux dies? |
| 353 | else if (returnCode == PLDM_REQUESTER_RECV_FAIL) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 354 | { |
Deepak Kodihalli | 23c5204 | 2020-09-01 03:04:32 -0500 | [diff] [blame] | 355 | // MCTP daemon has closed the socket this daemon is connected to. |
| 356 | // This may or may not be an error scenario, in either case the |
| 357 | // recovery mechanism for this daemon is to restart, and hence exit |
| 358 | // the event loop, that will cause this daemon to exit with a |
| 359 | // failure code. |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 360 | error("io exiting"); |
Deepak Kodihalli | 23c5204 | 2020-09-01 03:04:32 -0500 | [diff] [blame] | 361 | io.get_event().exit(0); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 362 | } |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 363 | else |
| 364 | { |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 365 | warning("Failed to receive PLDM request: {RETURN_CODE}", |
| 366 | "RETURN_CODE", returnCode); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 367 | } |
Thu Nguyen | efacb6f | 2024-04-12 01:37:46 +0000 | [diff] [blame^] | 368 | /* Free requestMsg after using */ |
| 369 | free(requestMsg); |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 370 | }; |
| 371 | |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 372 | bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); |
| 373 | bus.request_name("xyz.openbmc_project.PLDM"); |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 374 | IO io(event, pldmTransport.getEventSource(), EPOLLIN, std::move(callback)); |
Manojkiran Eda | 88bc718 | 2021-09-08 18:37:30 +0530 | [diff] [blame] | 375 | #ifdef LIBPLDMRESPONDER |
| 376 | if (hostPDRHandler) |
| 377 | { |
| 378 | hostPDRHandler->setHostFirmwareCondition(); |
| 379 | } |
| 380 | #endif |
Manojkiran Eda | ef77305 | 2021-07-29 09:29:28 +0530 | [diff] [blame] | 381 | stdplus::signal::block(SIGUSR1); |
| 382 | sdeventplus::source::Signal sigUsr1( |
| 383 | event, SIGUSR1, std::bind_front(&interruptFlightRecorderCallBack)); |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 384 | int returnCode = event.loop(); |
Brad Bishop | 3a22b97 | 2021-10-07 17:01:58 -0400 | [diff] [blame] | 385 | if (returnCode) |
| 386 | { |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 387 | exit(EXIT_FAILURE); |
| 388 | } |
Brad Bishop | 3a22b97 | 2021-10-07 17:01:58 -0400 | [diff] [blame] | 389 | |
| 390 | exit(EXIT_SUCCESS); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 391 | } |