blob: 01919b9131dae16a339a820d73cf3e398855f9f9 [file] [log] [blame]
Sampa Misra854e61f2019-08-22 04:36:47 -05001#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
21namespace pldm
22{
23namespace responder
24{
25
26using namespace phosphor::logging;
27
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060028int PelHandler::readIntoMemory(uint32_t /*offset*/, uint32_t& /*length*/,
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060029 uint64_t /*address*/)
30{
31 return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
32}
33
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060034int PelHandler::read(uint32_t /*offset*/, uint32_t& /*length*/,
35 Response& /*response*/)
36{
37 return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
38}
39
Sampa Misra854e61f2019-08-22 04:36:47 -050040int PelHandler::writeFromMemory(uint32_t offset, uint32_t length,
41 uint64_t address)
42{
43 fs::create_directories(PEL_TEMP_DIR);
44
45 auto timeMs =
46 std::chrono::duration_cast<std::chrono::milliseconds>(
47 std::chrono::high_resolution_clock::now().time_since_epoch())
48 .count();
49 std::string fileName(PEL_TEMP_DIR);
50 fileName += "/pel." + std::to_string(timeMs);
51 fs::path path(std::move(fileName));
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
62int 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 {
88 log<level::ERR>("failed to make a d-bus call to PEL daemon",
89 entry("ERROR=%s", e.what()));
90 return PLDM_ERROR;
91 }
92
93 return PLDM_SUCCESS;
94}
95
96} // namespace responder
97} // namespace pldm