blob: a5fa49a1f3def2ba46096204463df8d75e22cca2 [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{
Sampa Misraf5087a42019-12-03 04:51:36 -060043 char tmpFile[] = "/tmp/pel.XXXXXX";
44 int fd = mkstemp(tmpFile);
45 if (fd == -1)
46 {
47 log<level::ERR>("failed to create a temporary pel",
48 entry("ERROR=%d", errno));
49 return PLDM_ERROR;
50 }
51 close(fd);
52 fs::path path(tmpFile);
Sampa Misra854e61f2019-08-22 04:36:47 -050053
54 auto rc = transferFileData(path, false, offset, length, address);
55 if (rc == PLDM_SUCCESS)
56 {
57 rc = storePel(path.string());
58 }
59 fs::remove(path);
60 return rc;
61}
62
63int PelHandler::storePel(std::string&& pelFileName)
64{
65 static constexpr auto logObjPath = "/xyz/openbmc_project/logging";
66 static constexpr auto logInterface = "xyz.openbmc_project.Logging.Create";
67
68 static sdbusplus::bus::bus bus = sdbusplus::bus::new_default();
69
70 try
71 {
72 auto service = getService(bus, logObjPath, logInterface);
73 using namespace sdbusplus::xyz::openbmc_project::Logging::server;
74 std::map<std::string, std::string> addlData{};
75 addlData.emplace("RAWPEL", std::move(pelFileName));
76 auto severity =
77 sdbusplus::xyz::openbmc_project::Logging::server::convertForMessage(
78 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level::
79 Error);
80
81 auto method = bus.new_method_call(service.c_str(), logObjPath,
82 logInterface, "Create");
83 method.append("xyz.openbmc_project.Host.Error.Event", severity,
84 addlData);
85 bus.call_noreply(method);
86 }
87 catch (const std::exception& e)
88 {
89 log<level::ERR>("failed to make a d-bus call to PEL daemon",
90 entry("ERROR=%s", e.what()));
91 return PLDM_ERROR;
92 }
93
94 return PLDM_SUCCESS;
95}
96
97} // namespace responder
98} // namespace pldm