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" |
Gilbert Chen | 6c7fed4 | 2022-02-22 15:40:17 +0000 | [diff] [blame] | 9 | #include "platform-mc/manager.hpp" |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 10 | #include "requester/handler.hpp" |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 11 | #include "requester/mctp_endpoint_discovery.hpp" |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 12 | #include "requester/request.hpp" |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 13 | |
| 14 | #include <err.h> |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 15 | #include <getopt.h> |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 16 | #include <libpldm/base.h> |
| 17 | #include <libpldm/bios.h> |
| 18 | #include <libpldm/pdr.h> |
| 19 | #include <libpldm/platform.h> |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 20 | #include <libpldm/transport.h> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 21 | #include <poll.h> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 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> |
Pavithra Barithaya | b3b84b4 | 2024-08-23 11:43:57 +0530 | [diff] [blame] | 34 | #include <cstdlib> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 35 | #include <cstring> |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 36 | #include <fstream> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 37 | #include <iomanip> |
| 38 | #include <iterator> |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 39 | #include <memory> |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 40 | #include <ranges> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 41 | #include <sstream> |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 42 | #include <stdexcept> |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 43 | #include <string> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 44 | #include <vector> |
| 45 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 46 | PHOSPHOR_LOG2_USING; |
| 47 | |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 48 | #ifdef LIBPLDMRESPONDER |
| 49 | #include "dbus_impl_pdr.hpp" |
| 50 | #include "host-bmc/dbus_to_event_handler.hpp" |
Thu Nguyen | a34a64b | 2022-03-31 08:56:39 +0700 | [diff] [blame] | 51 | #include "host-bmc/dbus_to_terminus_effecters.hpp" |
Tom Joseph | 20aa3e0 | 2021-08-17 04:44:19 -0700 | [diff] [blame] | 52 | #include "host-bmc/host_condition.hpp" |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 53 | #include "host-bmc/host_pdr_handler.hpp" |
| 54 | #include "libpldmresponder/base.hpp" |
| 55 | #include "libpldmresponder/bios.hpp" |
| 56 | #include "libpldmresponder/fru.hpp" |
| 57 | #include "libpldmresponder/oem_handler.hpp" |
| 58 | #include "libpldmresponder/platform.hpp" |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 59 | #include "libpldmresponder/platform_config.hpp" |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 60 | #include "xyz/openbmc_project/PLDM/Event/server.hpp" |
| 61 | #endif |
| 62 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 63 | #ifdef OEM_IBM |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 64 | #include "oem_ibm.hpp" |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 65 | #endif |
| 66 | |
Chau Ly | a743e38 | 2024-10-26 11:12:22 +0000 | [diff] [blame] | 67 | #ifdef OEM_AMPERE |
| 68 | #include "oem/ampere/oem_ampere.hpp" |
| 69 | #endif |
| 70 | |
Thu Nguyen | 3f5a969 | 2024-07-16 13:16:54 +0000 | [diff] [blame] | 71 | constexpr const char* PLDMService = "xyz.openbmc_project.PLDM"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 72 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 73 | using namespace pldm; |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 74 | using namespace sdeventplus; |
| 75 | using namespace sdeventplus::source; |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 76 | using namespace pldm::responder; |
| 77 | using namespace pldm::utils; |
Manojkiran Eda | ef77305 | 2021-07-29 09:29:28 +0530 | [diff] [blame] | 78 | using sdeventplus::source::Signal; |
| 79 | using namespace pldm::flightrecorder; |
| 80 | |
| 81 | void interruptFlightRecorderCallBack(Signal& /*signal*/, |
| 82 | const struct signalfd_siginfo*) |
| 83 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 84 | error("Received SIGUR1(10) Signal interrupt"); |
Manojkiran Eda | ef77305 | 2021-07-29 09:29:28 +0530 | [diff] [blame] | 85 | // obtain the flight recorder instance and dump the recorder |
| 86 | FlightRecorder::GetInstance().playRecorder(); |
| 87 | } |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 88 | |
Archana Kakani | 62dd8ff | 2024-02-12 10:00:40 -0600 | [diff] [blame] | 89 | void requestPLDMServiceName() |
| 90 | { |
Thu Nguyen | 3f5a969 | 2024-07-16 13:16:54 +0000 | [diff] [blame] | 91 | try |
| 92 | { |
| 93 | auto& bus = pldm::utils::DBusHandler::getBus(); |
| 94 | bus.request_name(PLDMService); |
| 95 | } |
| 96 | catch (const sdbusplus::exception_t& e) |
| 97 | { |
| 98 | error("Failed to request D-Bus name {NAME} with error {ERROR}.", "NAME", |
| 99 | PLDMService, "ERROR", e); |
| 100 | } |
Archana Kakani | 62dd8ff | 2024-02-12 10:00:40 -0600 | [diff] [blame] | 101 | } |
| 102 | |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 103 | static std::optional<Response> |
| 104 | processRxMsg(const std::vector<uint8_t>& requestMsg, Invoker& invoker, |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 105 | requester::Handler<requester::Request>& handler, |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 106 | fw_update::Manager* fwManager, pldm_tid_t tid) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 107 | { |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 108 | uint8_t eid = tid; |
| 109 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 110 | pldm_header_info hdrFields{}; |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 111 | auto hdr = reinterpret_cast<const pldm_msg_hdr*>(requestMsg.data()); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 112 | if (PLDM_SUCCESS != unpack_pldm_header(hdr, &hdrFields)) |
| 113 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 114 | error("Empty PLDM request header"); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 115 | return std::nullopt; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 116 | } |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 117 | |
| 118 | if (PLDM_RESPONSE != hdrFields.msg_type) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 119 | { |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 120 | Response response; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 121 | auto request = reinterpret_cast<const pldm_msg*>(hdr); |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 122 | size_t requestLen = requestMsg.size() - sizeof(struct pldm_msg_hdr); |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 123 | try |
| 124 | { |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 125 | if (hdrFields.pldm_type != PLDM_FWUP) |
| 126 | { |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 127 | response = |
| 128 | invoker.handle(tid, hdrFields.pldm_type, hdrFields.command, |
| 129 | request, requestLen); |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 130 | } |
| 131 | else |
| 132 | { |
| 133 | response = fwManager->handleRequest(eid, hdrFields.command, |
| 134 | request, requestLen); |
| 135 | } |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 136 | } |
| 137 | catch (const std::out_of_range& e) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 138 | { |
| 139 | uint8_t completion_code = PLDM_ERROR_UNSUPPORTED_PLDM_CMD; |
| 140 | response.resize(sizeof(pldm_msg_hdr)); |
| 141 | auto responseHdr = reinterpret_cast<pldm_msg_hdr*>(response.data()); |
| 142 | pldm_header_info header{}; |
| 143 | header.msg_type = PLDM_RESPONSE; |
| 144 | header.instance = hdrFields.instance; |
| 145 | header.pldm_type = hdrFields.pldm_type; |
| 146 | header.command = hdrFields.command; |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 147 | if (PLDM_SUCCESS != pack_pldm_header(&header, responseHdr)) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 148 | { |
Riya Dixit | 087a751 | 2024-04-06 14:28:08 -0500 | [diff] [blame] | 149 | error( |
| 150 | "Failed to add response header for processing Rx, error - {ERROR}", |
| 151 | "ERROR", e); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 152 | return std::nullopt; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 153 | } |
| 154 | response.insert(response.end(), completion_code); |
| 155 | } |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 156 | return response; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 157 | } |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 158 | else if (PLDM_RESPONSE == hdrFields.msg_type) |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 159 | { |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 160 | auto response = reinterpret_cast<const pldm_msg*>(hdr); |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 161 | size_t responseLen = requestMsg.size() - sizeof(struct pldm_msg_hdr); |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 162 | handler.handleResponse(eid, hdrFields.instance, hdrFields.pldm_type, |
| 163 | hdrFields.command, response, responseLen); |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 164 | } |
Tom Joseph | 74f27c7 | 2021-05-16 07:58:53 -0700 | [diff] [blame] | 165 | return std::nullopt; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 166 | } |
| 167 | |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 168 | void optionUsage(void) |
| 169 | { |
Riya Dixit | 797f338 | 2023-08-22 22:27:51 -0500 | [diff] [blame] | 170 | info("Usage: pldmd [options]"); |
| 171 | info("Options:"); |
| 172 | info(" [--verbose] - would enable verbosity"); |
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 | int main(int argc, char** argv) |
| 176 | { |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 177 | bool verbose = false; |
Manojkiran Eda | f25145f | 2022-09-10 01:43:39 -0500 | [diff] [blame] | 178 | static struct option long_options[] = {{"verbose", no_argument, 0, 'v'}, |
| 179 | {0, 0, 0, 0}}; |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 180 | |
Manojkiran Eda | f25145f | 2022-09-10 01:43:39 -0500 | [diff] [blame] | 181 | auto argflag = getopt_long(argc, argv, "v", long_options, nullptr); |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 182 | switch (argflag) |
| 183 | { |
| 184 | case 'v': |
Manojkiran Eda | f25145f | 2022-09-10 01:43:39 -0500 | [diff] [blame] | 185 | verbose = true; |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 186 | break; |
Brad Bishop | c80f3ef | 2021-10-07 16:34:13 -0400 | [diff] [blame] | 187 | case -1: |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 188 | break; |
Brad Bishop | c80f3ef | 2021-10-07 16:34:13 -0400 | [diff] [blame] | 189 | default: |
Manojkiran Eda | f25145f | 2022-09-10 01:43:39 -0500 | [diff] [blame] | 190 | optionUsage(); |
Brad Bishop | c80f3ef | 2021-10-07 16:34:13 -0400 | [diff] [blame] | 191 | exit(EXIT_FAILURE); |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 192 | } |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 193 | // Setup PLDM requester transport |
| 194 | auto hostEID = pldm::utils::readHostEID(); |
| 195 | /* To maintain current behaviour until we have the infrastructure to find |
| 196 | * and use the correct TIDs */ |
| 197 | pldm_tid_t TID = hostEID; |
| 198 | PldmTransport pldmTransport{}; |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 199 | auto event = Event::get_default(); |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 200 | auto& bus = pldm::utils::DBusHandler::getBus(); |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 201 | sdbusplus::server::manager_t objManager(bus, |
| 202 | "/xyz/openbmc_project/software"); |
Gilbert Chen | eac61a4 | 2022-02-23 20:56:19 +0000 | [diff] [blame] | 203 | sdbusplus::server::manager_t sensorObjManager( |
| 204 | bus, "/xyz/openbmc_project/sensors"); |
Andrew Jeffery | 7c1dc7e | 2023-04-28 14:52:16 +0930 | [diff] [blame] | 205 | |
| 206 | InstanceIdDb instanceIdDb; |
| 207 | dbus_api::Requester dbusImplReq(bus, "/xyz/openbmc_project/pldm", |
| 208 | instanceIdDb); |
Patrick Williams | 705fa98 | 2023-09-27 02:32:20 -0500 | [diff] [blame] | 209 | sdbusplus::server::manager_t inventoryManager( |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 210 | bus, "/xyz/openbmc_project/inventory"); |
Pavithra Barithaya | 319ebb3 | 2021-05-06 06:09:11 -0500 | [diff] [blame] | 211 | |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 212 | Invoker invoker{}; |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 213 | requester::Handler<requester::Request> reqHandler(&pldmTransport, event, |
| 214 | instanceIdDb, verbose); |
Manojkiran Eda | 9fffea2 | 2021-10-27 16:03:27 +0530 | [diff] [blame] | 215 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 216 | std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)> pdrRepo( |
| 217 | pldm_pdr_init(), pldm_pdr_destroy); |
Andrew Jeffery | acb2029 | 2023-06-30 11:47:44 +0930 | [diff] [blame] | 218 | if (!pdrRepo) |
| 219 | { |
| 220 | throw std::runtime_error("Failed to instantiate PDR repository"); |
| 221 | } |
Thu Nguyen | a34a64b | 2022-03-31 08:56:39 +0700 | [diff] [blame] | 222 | DBusHandler dbusHandler; |
| 223 | std::unique_ptr<pldm::host_effecters::HostEffecterParser> |
| 224 | hostEffecterParser = |
| 225 | std::make_unique<pldm::host_effecters::HostEffecterParser>( |
| 226 | &instanceIdDb, pldmTransport.getEventSource(), pdrRepo.get(), |
| 227 | &dbusHandler, HOST_JSONS_DIR, &reqHandler); |
| 228 | #ifdef LIBPLDMRESPONDER |
| 229 | using namespace pldm::state_sensor; |
| 230 | dbus_api::Host dbusImplHost(bus, "/xyz/openbmc_project/pldm"); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 231 | std::unique_ptr<pldm_entity_association_tree, |
| 232 | decltype(&pldm_entity_association_tree_destroy)> |
| 233 | entityTree(pldm_entity_association_tree_init(), |
| 234 | pldm_entity_association_tree_destroy); |
Andrew Jeffery | abcd6ca | 2023-06-30 13:53:35 +0930 | [diff] [blame] | 235 | if (!entityTree) |
| 236 | { |
| 237 | throw std::runtime_error( |
| 238 | "Failed to instantiate general PDR entity association tree"); |
| 239 | } |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 240 | std::unique_ptr<pldm_entity_association_tree, |
| 241 | decltype(&pldm_entity_association_tree_destroy)> |
| 242 | bmcEntityTree(pldm_entity_association_tree_init(), |
| 243 | pldm_entity_association_tree_destroy); |
Andrew Jeffery | abcd6ca | 2023-06-30 13:53:35 +0930 | [diff] [blame] | 244 | if (!bmcEntityTree) |
| 245 | { |
| 246 | throw std::runtime_error( |
| 247 | "Failed to instantiate BMC PDR entity association tree"); |
| 248 | } |
Pavithra Barithaya | 319ebb3 | 2021-05-06 06:09:11 -0500 | [diff] [blame] | 249 | std::shared_ptr<HostPDRHandler> hostPDRHandler; |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 250 | std::unique_ptr<DbusToPLDMEvent> dbusToPLDMEventHandler; |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 251 | std::unique_ptr<platform_config::Handler> platformConfigHandler{}; |
Kamalkumar Patel | 0a42269 | 2024-06-03 00:42:56 -0500 | [diff] [blame] | 252 | platformConfigHandler = |
| 253 | std::make_unique<platform_config::Handler>(PDR_JSONS_DIR); |
Pavithra Barithaya | a410c65 | 2021-07-22 01:32:47 -0500 | [diff] [blame] | 254 | |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 255 | if (hostEID) |
| 256 | { |
| 257 | hostPDRHandler = std::make_shared<HostPDRHandler>( |
| 258 | pldmTransport.getEventSource(), hostEID, event, pdrRepo.get(), |
| 259 | EVENTS_JSONS_DIR, entityTree.get(), bmcEntityTree.get(), |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 260 | instanceIdDb, &reqHandler); |
| 261 | |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 262 | // HostFirmware interface needs access to hostPDR to know if host |
| 263 | // is running |
| 264 | dbusImplHost.setHostPdrObj(hostPDRHandler); |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 265 | |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 266 | dbusToPLDMEventHandler = std::make_unique<DbusToPLDMEvent>( |
| 267 | pldmTransport.getEventSource(), hostEID, instanceIdDb, &reqHandler); |
| 268 | } |
Pavithra Barithaya | a410c65 | 2021-07-22 01:32:47 -0500 | [diff] [blame] | 269 | |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 270 | auto fruHandler = std::make_unique<fru::Handler>( |
Manojkiran Eda | 03b01ca | 2021-06-29 08:55:09 +0530 | [diff] [blame] | 271 | FRU_JSONS_DIR, FRU_MASTER_JSON, pdrRepo.get(), entityTree.get(), |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 272 | bmcEntityTree.get()); |
Pavithra Barithaya | a410c65 | 2021-07-22 01:32:47 -0500 | [diff] [blame] | 273 | |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 274 | // FRU table is built lazily when a FRU command or Get PDR command is |
| 275 | // handled. To enable building FRU table, the FRU handler is passed to the |
| 276 | // Platform handler. |
Gilbert Chen | 77e6fe7 | 2024-08-06 09:23:30 +0000 | [diff] [blame] | 277 | |
| 278 | std::unique_ptr<platform_mc::Manager> platformManager = |
| 279 | std::make_unique<platform_mc::Manager>(event, reqHandler, instanceIdDb); |
| 280 | |
| 281 | pldm::responder::platform::EventMap addOnEventHandlers{ |
Thu Nguyen | 9fc7912 | 2024-09-10 10:15:01 +0000 | [diff] [blame] | 282 | {PLDM_CPER_EVENT, |
| 283 | {[&platformManager](const pldm_msg* request, size_t payloadLength, |
| 284 | uint8_t formatVersion, uint8_t tid, |
| 285 | size_t eventDataOffset) { |
| 286 | return platformManager->handleCperEvent( |
| 287 | request, payloadLength, formatVersion, tid, eventDataOffset); |
| 288 | }}}, |
Dung Cao | f48015b | 2023-11-21 04:38:29 +0000 | [diff] [blame] | 289 | {PLDM_MESSAGE_POLL_EVENT, |
| 290 | {[&platformManager](const pldm_msg* request, size_t payloadLength, |
| 291 | uint8_t formatVersion, uint8_t tid, |
| 292 | size_t eventDataOffset) { |
| 293 | return platformManager->handlePldmMessagePollEvent( |
| 294 | request, payloadLength, formatVersion, tid, eventDataOffset); |
| 295 | }}}, |
Gilbert Chen | 77e6fe7 | 2024-08-06 09:23:30 +0000 | [diff] [blame] | 296 | {PLDM_SENSOR_EVENT, |
| 297 | {[&platformManager](const pldm_msg* request, size_t payloadLength, |
| 298 | uint8_t formatVersion, uint8_t tid, |
| 299 | size_t eventDataOffset) { |
| 300 | return platformManager->handleSensorEvent( |
| 301 | request, payloadLength, formatVersion, tid, eventDataOffset); |
| 302 | }}}}; |
| 303 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 304 | auto platformHandler = std::make_unique<platform::Handler>( |
Sagar Srinivas | 90314a3 | 2023-10-17 10:38:03 -0500 | [diff] [blame] | 305 | &dbusHandler, hostEID, &instanceIdDb, PDR_JSONS_DIR, pdrRepo.get(), |
| 306 | hostPDRHandler.get(), dbusToPLDMEventHandler.get(), fruHandler.get(), |
Gilbert Chen | 77e6fe7 | 2024-08-06 09:23:30 +0000 | [diff] [blame] | 307 | platformConfigHandler.get(), &reqHandler, event, true, |
| 308 | addOnEventHandlers); |
Pavithra Barithaya | a410c65 | 2021-07-22 01:32:47 -0500 | [diff] [blame] | 309 | |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 310 | auto biosHandler = std::make_unique<bios::Handler>( |
| 311 | pldmTransport.getEventSource(), hostEID, &instanceIdDb, &reqHandler, |
| 312 | platformConfigHandler.get(), requestPLDMServiceName); |
| 313 | |
| 314 | auto baseHandler = std::make_unique<base::Handler>(event); |
| 315 | |
Chau Ly | a743e38 | 2024-10-26 11:12:22 +0000 | [diff] [blame] | 316 | #ifdef OEM_AMPERE |
| 317 | pldm::oem_ampere::OemAMPERE oemAMPERE( |
| 318 | &dbusHandler, pldmTransport.getEventSource(), pdrRepo.get(), |
| 319 | instanceIdDb, event, invoker, hostPDRHandler.get(), |
| 320 | platformHandler.get(), fruHandler.get(), baseHandler.get(), |
| 321 | biosHandler.get(), platformManager.get(), &reqHandler); |
| 322 | #endif |
| 323 | |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 324 | #ifdef OEM_IBM |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 325 | pldm::oem_ibm::OemIBM oemIBM( |
| 326 | &dbusHandler, pldmTransport.getEventSource(), hostEID, pdrRepo.get(), |
| 327 | instanceIdDb, event, invoker, hostPDRHandler.get(), |
| 328 | platformHandler.get(), fruHandler.get(), baseHandler.get(), |
| 329 | &reqHandler); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 330 | #endif |
| 331 | |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 332 | invoker.registerHandler(PLDM_BIOS, std::move(biosHandler)); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 333 | invoker.registerHandler(PLDM_PLATFORM, std::move(platformHandler)); |
| 334 | invoker.registerHandler(PLDM_FRU, std::move(fruHandler)); |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 335 | invoker.registerHandler(PLDM_BASE, std::move(baseHandler)); |
| 336 | |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 337 | dbus_api::Pdr dbusImplPdr(bus, "/xyz/openbmc_project/pldm", pdrRepo.get()); |
| 338 | sdbusplus::xyz::openbmc_project::PLDM::server::Event dbusImplEvent( |
| 339 | bus, "/xyz/openbmc_project/pldm"); |
Tom Joseph | 20aa3e0 | 2021-08-17 04:44:19 -0700 | [diff] [blame] | 340 | |
Tom Joseph | 02b4ee4 | 2021-05-02 22:44:36 -0700 | [diff] [blame] | 341 | #endif |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 342 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 343 | std::unique_ptr<fw_update::Manager> fwManager = |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 344 | std::make_unique<fw_update::Manager>(event, reqHandler, instanceIdDb); |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 345 | std::unique_ptr<MctpDiscovery> mctpDiscoveryHandler = |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 346 | std::make_unique<MctpDiscovery>( |
Gilbert Chen | 6c7fed4 | 2022-02-22 15:40:17 +0000 | [diff] [blame] | 347 | bus, std::initializer_list<MctpDiscoveryHandlerIntf*>{ |
| 348 | fwManager.get(), platformManager.get()}); |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 349 | auto callback = [verbose, &invoker, &reqHandler, &fwManager, &pldmTransport, |
| 350 | TID](IO& io, int fd, uint32_t revents) mutable { |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 351 | if (!(revents & EPOLLIN)) |
| 352 | { |
| 353 | return; |
| 354 | } |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 355 | if (fd < 0) |
| 356 | { |
| 357 | return; |
| 358 | } |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 359 | |
| 360 | int returnCode = 0; |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 361 | void* requestMsg; |
| 362 | size_t recvDataLength; |
| 363 | returnCode = pldmTransport.recvMsg(TID, requestMsg, recvDataLength); |
| 364 | |
| 365 | if (returnCode == PLDM_REQUESTER_SUCCESS) |
| 366 | { |
| 367 | std::vector<uint8_t> requestMsgVec( |
| 368 | static_cast<uint8_t*>(requestMsg), |
| 369 | static_cast<uint8_t*>(requestMsg) + recvDataLength); |
| 370 | FlightRecorder::GetInstance().saveRecord(requestMsgVec, false); |
| 371 | if (verbose) |
| 372 | { |
| 373 | printBuffer(Rx, requestMsgVec); |
| 374 | } |
| 375 | // process message and send response |
| 376 | auto response = processRxMsg(requestMsgVec, invoker, reqHandler, |
| 377 | fwManager.get(), TID); |
| 378 | if (response.has_value()) |
| 379 | { |
| 380 | FlightRecorder::GetInstance().saveRecord(*response, true); |
| 381 | if (verbose) |
| 382 | { |
| 383 | printBuffer(Tx, *response); |
| 384 | } |
| 385 | |
| 386 | returnCode = pldmTransport.sendMsg(TID, (*response).data(), |
| 387 | (*response).size()); |
| 388 | if (returnCode != PLDM_REQUESTER_SUCCESS) |
| 389 | { |
Riya Dixit | 087a751 | 2024-04-06 14:28:08 -0500 | [diff] [blame] | 390 | warning( |
| 391 | "Failed to send pldmTransport message for TID '{TID}', response code '{RETURN_CODE}'", |
| 392 | "TID", TID, "RETURN_CODE", returnCode); |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | } |
| 396 | // TODO check that we get here if mctp-demux dies? |
| 397 | else if (returnCode == PLDM_REQUESTER_RECV_FAIL) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 398 | { |
Deepak Kodihalli | 23c5204 | 2020-09-01 03:04:32 -0500 | [diff] [blame] | 399 | // MCTP daemon has closed the socket this daemon is connected to. |
| 400 | // This may or may not be an error scenario, in either case the |
| 401 | // recovery mechanism for this daemon is to restart, and hence exit |
| 402 | // the event loop, that will cause this daemon to exit with a |
| 403 | // failure code. |
Riya Dixit | 087a751 | 2024-04-06 14:28:08 -0500 | [diff] [blame] | 404 | error( |
| 405 | "MCTP daemon closed the socket, IO exiting with response code '{RC}'", |
| 406 | "RC", returnCode); |
Deepak Kodihalli | 23c5204 | 2020-09-01 03:04:32 -0500 | [diff] [blame] | 407 | io.get_event().exit(0); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 408 | } |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 409 | else |
| 410 | { |
Riya Dixit | 087a751 | 2024-04-06 14:28:08 -0500 | [diff] [blame] | 411 | warning( |
| 412 | "Failed to receive PLDM request for pldmTransport, response code '{RETURN_CODE}'", |
| 413 | "RETURN_CODE", returnCode); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 414 | } |
Thu Nguyen | efacb6f | 2024-04-12 01:37:46 +0000 | [diff] [blame] | 415 | /* Free requestMsg after using */ |
| 416 | free(requestMsg); |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 417 | }; |
| 418 | |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 419 | bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); |
Archana Kakani | 46f352e | 2024-03-17 08:21:08 -0500 | [diff] [blame] | 420 | #ifndef SYSTEM_SPECIFIC_BIOS_JSON |
Thu Nguyen | 3f5a969 | 2024-07-16 13:16:54 +0000 | [diff] [blame] | 421 | try |
| 422 | { |
| 423 | bus.request_name(PLDMService); |
| 424 | } |
| 425 | catch (const sdbusplus::exception_t& e) |
| 426 | { |
| 427 | error("Failed to request D-Bus name {NAME} with error {ERROR}.", "NAME", |
| 428 | PLDMService, "ERROR", e); |
| 429 | } |
Archana Kakani | 46f352e | 2024-03-17 08:21:08 -0500 | [diff] [blame] | 430 | #endif |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 431 | IO io(event, pldmTransport.getEventSource(), EPOLLIN, std::move(callback)); |
Manojkiran Eda | 88bc718 | 2021-09-08 18:37:30 +0530 | [diff] [blame] | 432 | #ifdef LIBPLDMRESPONDER |
| 433 | if (hostPDRHandler) |
| 434 | { |
| 435 | hostPDRHandler->setHostFirmwareCondition(); |
| 436 | } |
| 437 | #endif |
Manojkiran Eda | ef77305 | 2021-07-29 09:29:28 +0530 | [diff] [blame] | 438 | stdplus::signal::block(SIGUSR1); |
| 439 | sdeventplus::source::Signal sigUsr1( |
| 440 | event, SIGUSR1, std::bind_front(&interruptFlightRecorderCallBack)); |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 441 | int returnCode = event.loop(); |
Brad Bishop | 3a22b97 | 2021-10-07 17:01:58 -0400 | [diff] [blame] | 442 | if (returnCode) |
| 443 | { |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 444 | exit(EXIT_FAILURE); |
| 445 | } |
Brad Bishop | 3a22b97 | 2021-10-07 17:01:58 -0400 | [diff] [blame] | 446 | |
| 447 | exit(EXIT_SUCCESS); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 448 | } |