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> |
| 14 | #include <sdbusplus/server.hpp> |
| 15 | #include <vector> |
| 16 | #include <xyz/openbmc_project/Logging/Entry/server.hpp> |
| 17 | |
| 18 | #include "libpldm/base.h" |
| 19 | #include "oem/ibm/libpldm/file_io.h" |
| 20 | |
| 21 | namespace pldm |
| 22 | { |
| 23 | namespace responder |
| 24 | { |
| 25 | |
| 26 | using namespace phosphor::logging; |
| 27 | |
Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame^] | 28 | int PelHandler::readIntoMemory(uint32_t /*offset*/, uint32_t /*length*/, |
| 29 | uint64_t /*address*/) |
| 30 | { |
| 31 | return PLDM_ERROR_UNSUPPORTED_PLDM_CMD; |
| 32 | } |
| 33 | |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 34 | int PelHandler::writeFromMemory(uint32_t offset, uint32_t length, |
| 35 | uint64_t address) |
| 36 | { |
| 37 | fs::create_directories(PEL_TEMP_DIR); |
| 38 | |
| 39 | auto timeMs = |
| 40 | std::chrono::duration_cast<std::chrono::milliseconds>( |
| 41 | std::chrono::high_resolution_clock::now().time_since_epoch()) |
| 42 | .count(); |
| 43 | std::string fileName(PEL_TEMP_DIR); |
| 44 | fileName += "/pel." + std::to_string(timeMs); |
| 45 | fs::path path(std::move(fileName)); |
| 46 | |
| 47 | auto rc = transferFileData(path, false, offset, length, address); |
| 48 | if (rc == PLDM_SUCCESS) |
| 49 | { |
| 50 | rc = storePel(path.string()); |
| 51 | } |
| 52 | fs::remove(path); |
| 53 | return rc; |
| 54 | } |
| 55 | |
| 56 | int PelHandler::storePel(std::string&& pelFileName) |
| 57 | { |
| 58 | static constexpr auto logObjPath = "/xyz/openbmc_project/logging"; |
| 59 | static constexpr auto logInterface = "xyz.openbmc_project.Logging.Create"; |
| 60 | |
| 61 | static sdbusplus::bus::bus bus = sdbusplus::bus::new_default(); |
| 62 | |
| 63 | try |
| 64 | { |
| 65 | auto service = getService(bus, logObjPath, logInterface); |
| 66 | using namespace sdbusplus::xyz::openbmc_project::Logging::server; |
| 67 | std::map<std::string, std::string> addlData{}; |
| 68 | addlData.emplace("RAWPEL", std::move(pelFileName)); |
| 69 | auto severity = |
| 70 | sdbusplus::xyz::openbmc_project::Logging::server::convertForMessage( |
| 71 | sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level:: |
| 72 | Error); |
| 73 | |
| 74 | auto method = bus.new_method_call(service.c_str(), logObjPath, |
| 75 | logInterface, "Create"); |
| 76 | method.append("xyz.openbmc_project.Host.Error.Event", severity, |
| 77 | addlData); |
| 78 | bus.call_noreply(method); |
| 79 | } |
| 80 | catch (const std::exception& e) |
| 81 | { |
| 82 | log<level::ERR>("failed to make a d-bus call to PEL daemon", |
| 83 | entry("ERROR=%s", e.what())); |
| 84 | return PLDM_ERROR; |
| 85 | } |
| 86 | |
| 87 | return PLDM_SUCCESS; |
| 88 | } |
| 89 | |
| 90 | } // namespace responder |
| 91 | } // namespace pldm |