blob: c919c27c73b955e80fe706b8e61c6f44950a344b [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>
Sampa Misraaa8ae722019-12-12 03:20:40 -060014#include <iostream>
Sampa Misra854e61f2019-08-22 04:36:47 -050015#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
22namespace pldm
23{
24namespace responder
25{
26
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060027int PelHandler::readIntoMemory(uint32_t /*offset*/, uint32_t& /*length*/,
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060028 uint64_t /*address*/)
29{
30 return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
31}
32
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060033int PelHandler::read(uint32_t /*offset*/, uint32_t& /*length*/,
34 Response& /*response*/)
35{
36 return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
37}
38
Sampa Misra854e61f2019-08-22 04:36:47 -050039int PelHandler::writeFromMemory(uint32_t offset, uint32_t length,
40 uint64_t address)
41{
Sampa Misraf5087a42019-12-03 04:51:36 -060042 char tmpFile[] = "/tmp/pel.XXXXXX";
43 int fd = mkstemp(tmpFile);
44 if (fd == -1)
45 {
Sampa Misraaa8ae722019-12-12 03:20:40 -060046 std::cerr << "failed to create a temporary pel, ERROR=" << errno
47 << "\n";
Sampa Misraf5087a42019-12-03 04:51:36 -060048 return PLDM_ERROR;
49 }
50 close(fd);
51 fs::path path(tmpFile);
Sampa Misra854e61f2019-08-22 04:36:47 -050052
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 {
Sampa Misraaa8ae722019-12-12 03:20:40 -060088 std::cerr << "failed to make a d-bus call to PEL daemon, ERROR="
89 << e.what() << "\n";
Sampa Misra854e61f2019-08-22 04:36:47 -050090 return PLDM_ERROR;
91 }
92
93 return PLDM_SUCCESS;
94}
95
96} // namespace responder
97} // namespace pldm