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 | |
| 28 | int PelHandler::writeFromMemory(uint32_t offset, uint32_t length, |
| 29 | uint64_t address) |
| 30 | { |
| 31 | fs::create_directories(PEL_TEMP_DIR); |
| 32 | |
| 33 | auto timeMs = |
| 34 | std::chrono::duration_cast<std::chrono::milliseconds>( |
| 35 | std::chrono::high_resolution_clock::now().time_since_epoch()) |
| 36 | .count(); |
| 37 | std::string fileName(PEL_TEMP_DIR); |
| 38 | fileName += "/pel." + std::to_string(timeMs); |
| 39 | fs::path path(std::move(fileName)); |
| 40 | |
| 41 | auto rc = transferFileData(path, false, offset, length, address); |
| 42 | if (rc == PLDM_SUCCESS) |
| 43 | { |
| 44 | rc = storePel(path.string()); |
| 45 | } |
| 46 | fs::remove(path); |
| 47 | return rc; |
| 48 | } |
| 49 | |
| 50 | int PelHandler::storePel(std::string&& pelFileName) |
| 51 | { |
| 52 | static constexpr auto logObjPath = "/xyz/openbmc_project/logging"; |
| 53 | static constexpr auto logInterface = "xyz.openbmc_project.Logging.Create"; |
| 54 | |
| 55 | static sdbusplus::bus::bus bus = sdbusplus::bus::new_default(); |
| 56 | |
| 57 | try |
| 58 | { |
| 59 | auto service = getService(bus, logObjPath, logInterface); |
| 60 | using namespace sdbusplus::xyz::openbmc_project::Logging::server; |
| 61 | std::map<std::string, std::string> addlData{}; |
| 62 | addlData.emplace("RAWPEL", std::move(pelFileName)); |
| 63 | auto severity = |
| 64 | sdbusplus::xyz::openbmc_project::Logging::server::convertForMessage( |
| 65 | sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level:: |
| 66 | Error); |
| 67 | |
| 68 | auto method = bus.new_method_call(service.c_str(), logObjPath, |
| 69 | logInterface, "Create"); |
| 70 | method.append("xyz.openbmc_project.Host.Error.Event", severity, |
| 71 | addlData); |
| 72 | bus.call_noreply(method); |
| 73 | } |
| 74 | catch (const std::exception& e) |
| 75 | { |
| 76 | log<level::ERR>("failed to make a d-bus call to PEL daemon", |
| 77 | entry("ERROR=%s", e.what())); |
| 78 | return PLDM_ERROR; |
| 79 | } |
| 80 | |
| 81 | return PLDM_SUCCESS; |
| 82 | } |
| 83 | |
| 84 | } // namespace responder |
| 85 | } // namespace pldm |