Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "file_io_type_pel.hpp" |
| 4 | |
| 5 | #include "libpldmresponder/utils.hpp" |
| 6 | #include "xyz/openbmc_project/Common/error.hpp" |
| 7 | |
| 8 | #include <stdint.h> |
| 9 | #include <systemd/sd-bus.h> |
| 10 | #include <unistd.h> |
| 11 | |
| 12 | #include <exception> |
| 13 | #include <filesystem> |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame^] | 14 | #include <iostream> |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 15 | #include <sdbusplus/server.hpp> |
| 16 | #include <vector> |
| 17 | #include <xyz/openbmc_project/Logging/Entry/server.hpp> |
| 18 | |
| 19 | #include "libpldm/base.h" |
| 20 | #include "oem/ibm/libpldm/file_io.h" |
| 21 | |
| 22 | namespace pldm |
| 23 | { |
| 24 | namespace responder |
| 25 | { |
| 26 | |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 27 | int PelHandler::readIntoMemory(uint32_t /*offset*/, uint32_t& /*length*/, |
Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame] | 28 | uint64_t /*address*/) |
| 29 | { |
| 30 | return PLDM_ERROR_UNSUPPORTED_PLDM_CMD; |
| 31 | } |
| 32 | |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 33 | int PelHandler::read(uint32_t /*offset*/, uint32_t& /*length*/, |
| 34 | Response& /*response*/) |
| 35 | { |
| 36 | return PLDM_ERROR_UNSUPPORTED_PLDM_CMD; |
| 37 | } |
| 38 | |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 39 | int PelHandler::writeFromMemory(uint32_t offset, uint32_t length, |
| 40 | uint64_t address) |
| 41 | { |
Sampa Misra | f5087a4 | 2019-12-03 04:51:36 -0600 | [diff] [blame] | 42 | char tmpFile[] = "/tmp/pel.XXXXXX"; |
| 43 | int fd = mkstemp(tmpFile); |
| 44 | if (fd == -1) |
| 45 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame^] | 46 | std::cerr << "failed to create a temporary pel, ERROR=" << errno |
| 47 | << "\n"; |
Sampa Misra | f5087a4 | 2019-12-03 04:51:36 -0600 | [diff] [blame] | 48 | return PLDM_ERROR; |
| 49 | } |
| 50 | close(fd); |
| 51 | fs::path path(tmpFile); |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 52 | |
| 53 | auto rc = transferFileData(path, false, offset, length, address); |
| 54 | if (rc == PLDM_SUCCESS) |
| 55 | { |
| 56 | rc = storePel(path.string()); |
| 57 | } |
| 58 | fs::remove(path); |
| 59 | return rc; |
| 60 | } |
| 61 | |
| 62 | int PelHandler::storePel(std::string&& pelFileName) |
| 63 | { |
| 64 | static constexpr auto logObjPath = "/xyz/openbmc_project/logging"; |
| 65 | static constexpr auto logInterface = "xyz.openbmc_project.Logging.Create"; |
| 66 | |
| 67 | static sdbusplus::bus::bus bus = sdbusplus::bus::new_default(); |
| 68 | |
| 69 | try |
| 70 | { |
| 71 | auto service = getService(bus, logObjPath, logInterface); |
| 72 | using namespace sdbusplus::xyz::openbmc_project::Logging::server; |
| 73 | std::map<std::string, std::string> addlData{}; |
| 74 | addlData.emplace("RAWPEL", std::move(pelFileName)); |
| 75 | auto severity = |
| 76 | sdbusplus::xyz::openbmc_project::Logging::server::convertForMessage( |
| 77 | sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level:: |
| 78 | Error); |
| 79 | |
| 80 | auto method = bus.new_method_call(service.c_str(), logObjPath, |
| 81 | logInterface, "Create"); |
| 82 | method.append("xyz.openbmc_project.Host.Error.Event", severity, |
| 83 | addlData); |
| 84 | bus.call_noreply(method); |
| 85 | } |
| 86 | catch (const std::exception& e) |
| 87 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame^] | 88 | std::cerr << "failed to make a d-bus call to PEL daemon, ERROR=" |
| 89 | << e.what() << "\n"; |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 90 | return PLDM_ERROR; |
| 91 | } |
| 92 | |
| 93 | return PLDM_SUCCESS; |
| 94 | } |
| 95 | |
| 96 | } // namespace responder |
| 97 | } // namespace pldm |