1 #include "error-HostEvent.hpp"
2 #include "sensorhandler.hpp"
3 #include "storagehandler.hpp"
4 
5 #include <systemd/sd-bus.h>
6 
7 #include <ipmid/api.hpp>
8 #include <ipmid/types.hpp>
9 #include <phosphor-logging/elog-errors.hpp>
10 #include <phosphor-logging/elog.hpp>
11 #include <phosphor-logging/lg2.hpp>
12 #include <xyz/openbmc_project/Logging/Entry/server.hpp>
13 
14 #include <algorithm>
15 #include <cstdlib>
16 #include <cstring>
17 #include <fstream>
18 #include <iostream>
19 #include <memory>
20 #include <vector>
21 
22 using namespace std;
23 using namespace phosphor::logging;
24 using namespace sdbusplus::server::xyz::openbmc_project::logging;
25 
readESEL(const char * fileName)26 std::string readESEL(const char* fileName)
27 {
28     std::string content;
29     std::ifstream handle(fileName);
30 
31     if (handle.fail())
32     {
33         lg2::error("Failed to open eSEL, file name: {FILENAME}", "FILENAME",
34                    fileName);
35         return content;
36     }
37 
38     handle.seekg(0, std::ios::end);
39     content.resize(handle.tellg());
40     handle.seekg(0, std::ios::beg);
41     handle.read(&content[0], content.size());
42     handle.close();
43 
44     return content;
45 }
46 
createProcedureLogEntry(uint8_t procedureNum)47 void createProcedureLogEntry(uint8_t procedureNum)
48 {
49     // Read the eSEL data from the file.
50     static constexpr auto eSELFile = "/tmp/esel";
51     auto eSELData = readESEL(eSELFile);
52 
53     // Each byte in eSEL is formatted as %02x with a space between bytes and
54     // insert '/0' at the end of the character array.
55     static constexpr auto byteSeparator = 3;
56     std::unique_ptr<char[]> data(
57         new char[(eSELData.size() * byteSeparator) + 1]());
58 
59     for (size_t i = 0; i < eSELData.size(); i++)
60     {
61         sprintf(&data[i * byteSeparator], "%02x ", eSELData[i]);
62     }
63     data[eSELData.size() * byteSeparator] = '\0';
64 
65     using error = sdbusplus::error::org::open_power::host::MaintenanceProcedure;
66     using metadata = org::open_power::host::MaintenanceProcedure;
67 
68     report<error>(metadata::ESEL(data.get()),
69                   metadata::PROCEDURE(static_cast<uint32_t>(procedureNum)));
70 }
71