blob: 3d50a3dea5e78348fc7c3faf7ae50bba61e7d528 [file] [log] [blame]
Tom Joseph6b7a1432017-05-19 10:43:36 +05301#pragma once
2
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05003#include <ipmid/types.hpp>
4#include <sdbusplus/server.hpp>
5
Yong Li021f2d12018-09-26 16:09:22 +08006#include <chrono>
Tom Joseph6b7a1432017-05-19 10:43:36 +05307#include <cstdint>
Lotus Xu57d35572021-01-24 11:13:13 +08008#include <iomanip>
9#include <iostream>
Lotus Xu57d35572021-01-24 11:13:13 +080010#include <sstream>
Tom Joseph6b7a1432017-05-19 10:43:36 +053011
12namespace ipmi
13{
14
15namespace sel
16{
17
George Liu656ae3c2024-08-23 16:44:22 +080018static constexpr auto logWatchPath = "/xyz/openbmc_project/logging";
Tom Joseph6b7a1432017-05-19 10:43:36 +053019static constexpr auto logBasePath = "/xyz/openbmc_project/logging/entry";
20static constexpr auto logEntryIntf = "xyz.openbmc_project.Logging.Entry";
21static constexpr auto logDeleteIntf = "xyz.openbmc_project.Object.Delete";
22
Lotus Xu78fe1b12021-05-23 17:26:56 +080023static constexpr auto logObj = "/xyz/openbmc_project/logging";
24static constexpr auto logIntf = "xyz.openbmc_project.Collection.DeleteAll";
25static constexpr auto logDeleteAllMethod = "DeleteAll";
26
Tom Joseph6b7a1432017-05-19 10:43:36 +053027static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
28
Tom Joseph232f5292017-07-07 20:14:02 +053029using ObjectPaths = std::vector<std::string>;
Tom Joseph306878b2017-07-10 19:30:54 +053030using PropertyName = std::string;
31using Resolved = bool;
32using Id = uint32_t;
33using Timestamp = uint64_t;
34using Message = std::string;
Patrick Williams39deff22024-12-11 21:12:59 -050035using AdditionalData = std::map<std::string, std::string>;
36using PropertyType =
37 std::variant<Resolved, Id, Timestamp, Message, AdditionalData>;
Tom Joseph6b7a1432017-05-19 10:43:36 +053038
Tom Joseph6f7deaa2017-06-30 19:03:54 +053039static constexpr auto selVersion = 0x51;
40static constexpr auto invalidTimeStamp = 0xFFFFFFFF;
Tom Joseph6f7deaa2017-06-30 19:03:54 +053041
Tom Josepha4953392017-06-30 19:09:47 +053042static constexpr auto firstEntry = 0x0000;
43static constexpr auto lastEntry = 0xFFFF;
44static constexpr auto entireRecord = 0xFF;
45static constexpr auto selRecordSize = 16;
46
jayaprakash Mutyalab7557722019-05-02 21:13:30 +000047namespace operationSupport
48{
49static constexpr bool overflow = false;
50static constexpr bool deleteSel = true;
51static constexpr bool partialAddSelEntry = false;
52static constexpr bool reserveSel = true;
53static constexpr bool getSelAllocationInfo = false;
54} // namespace operationSupport
55
Lei YUaf378fa2020-12-02 16:28:57 +080056constexpr size_t SELRecordLength = 16;
57
58/** @struct SELEventRecord
Tom Joseph6b7a1432017-05-19 10:43:36 +053059 *
Lei YUaf378fa2020-12-02 16:28:57 +080060 * IPMI SEL Event Record
Tom Joseph6b7a1432017-05-19 10:43:36 +053061 */
Lei YUaf378fa2020-12-02 16:28:57 +080062struct SELEventRecord
Tom Joseph6b7a1432017-05-19 10:43:36 +053063{
Patrick Venture0b02be92018-08-31 11:55:55 -070064 uint16_t recordID; //!< Record ID.
65 uint8_t recordType; //!< Record Type.
66 uint32_t timeStamp; //!< Timestamp.
67 uint16_t generatorID; //!< Generator ID.
68 uint8_t eventMsgRevision; //!< Event Message Revision.
69 uint8_t sensorType; //!< Sensor Type.
70 uint8_t sensorNum; //!< Sensor Number.
71 uint8_t eventType; //!< Event Dir | Event Type.
72 uint8_t eventData1; //!< Event Data 1.
73 uint8_t eventData2; //!< Event Data 2.
74 uint8_t eventData3; //!< Event Data 3.
Tom Joseph6b7a1432017-05-19 10:43:36 +053075} __attribute__((packed));
76
Lei YUaf378fa2020-12-02 16:28:57 +080077static_assert(sizeof(SELEventRecord) == SELRecordLength);
78
79/** @struct SELOEMRecordTypeCD
80 *
81 * IPMI SEL OEM Record - Type C0h-DFh
82 */
83struct SELOEMRecordTypeCD
84{
85 uint16_t recordID; //!< Record ID.
86 uint8_t recordType; //!< Record Type.
87 uint32_t timeStamp; //!< Timestamp.
88 uint8_t manufacturerID[3]; //!< Manufacturer ID.
89 uint8_t oemDefined[6]; //!< OEM Defined data.
90} __attribute__((packed));
91
92static_assert(sizeof(SELOEMRecordTypeCD) == SELRecordLength);
93
94/** @struct SELOEMRecordTypeEF
95 *
96 * IPMI SEL OEM Record - Type E0h-FFh
97 */
98struct SELOEMRecordTypeEF
99{
100 uint16_t recordID; //!< Record ID.
101 uint8_t recordType; //!< Record Type.
102 uint8_t oemDefined[13]; //!< OEM Defined data.
103} __attribute__((packed));
104
105static_assert(sizeof(SELOEMRecordTypeEF) == SELRecordLength);
106
107union SELEventRecordFormat
108{
109 SELEventRecord eventRecord;
110 SELOEMRecordTypeCD oemCD;
111 SELOEMRecordTypeEF oemEF;
112};
113
114/** @struct GetSELEntryResponse
115 *
116 * IPMI payload for Get SEL Entry command response.
117 */
118struct GetSELEntryResponse
119{
120 uint16_t nextRecordID; //!< Next RecordID.
121 SELEventRecordFormat event; // !< The Event Record.
122} __attribute__((packed));
123
124static_assert(sizeof(GetSELEntryResponse) ==
125 SELRecordLength + sizeof(uint16_t));
126
Tom Joseph2f05bb52017-06-30 19:14:49 +0530127static constexpr auto initiateErase = 0xAA;
128static constexpr auto getEraseStatus = 0x00;
129static constexpr auto eraseComplete = 0x01;
130
Tom Joseph6edc8a02017-06-30 18:52:56 +0530131/** @brief Convert logging entry to SEL
132 *
133 * @param[in] objPath - DBUS object path of the logging entry.
134 *
135 * @return On success return the response of Get SEL entry command.
136 */
137GetSELEntryResponse convertLogEntrytoSEL(const std::string& objPath);
138
Tom Joseph399fd922017-06-30 18:40:30 +0530139/** @brief Get the timestamp of the log entry
140 *
141 * @param[in] objPath - DBUS object path of the logging entry.
142 *
143 * @return On success return the timestamp of the log entry as number of
144 * seconds from epoch.
145 */
146std::chrono::seconds getEntryTimeStamp(const std::string& objPath);
Tom Joseph6edc8a02017-06-30 18:52:56 +0530147
Tom Joseph232f5292017-07-07 20:14:02 +0530148/** @brief Read the logging entry object paths
149 *
150 * This API would read the logging dbus logging entry object paths and sorting
151 * the filename in the numeric order. The paths is cleared before populating
152 * the object paths.
153 *
154 * @param[in,out] paths - sorted list of logging entry object paths.
155 *
156 * @note This function is invoked when the Get SEL Info command or the Delete
157 * SEL entry command is invoked. The Get SEL Entry command is preceded
158 * typically by Get SEL Info command, so readLoggingObjectPaths is not
159 * invoked before each Get SEL entry command.
160 */
161void readLoggingObjectPaths(ObjectPaths& paths);
162
Lotus Xu57d35572021-01-24 11:13:13 +0800163template <typename T>
164std::string toHexStr(const T& data)
165{
166 std::stringstream stream;
167 stream << std::hex << std::uppercase << std::setfill('0');
168 for (const auto& v : data)
169 {
170 stream << std::setw(2) << static_cast<int>(v);
171 }
172 return stream.str();
173}
Tom Joseph6b7a1432017-05-19 10:43:36 +0530174namespace internal
175{
176
177/** @brief Convert logging entry to SEL event record
178 *
179 * @param[in] objPath - DBUS object path of the logging entry.
180 * @param[in] iter - Iterator to the sensor data corresponding to the logging
181 * entry
182 *
183 * @return On success return the SEL event record, throw an exception in case
184 * of failure.
185 */
Patrick Williams69b4c282025-03-03 11:19:13 -0500186GetSELEntryResponse prepareSELEntry(
187 const std::string& objPath,
188 ipmi::sensor::InvObjectIDMap::const_iterator iter);
Tom Joseph6b7a1432017-05-19 10:43:36 +0530189
Patrick Venture0b02be92018-08-31 11:55:55 -0700190} // namespace internal
Tom Joseph6b7a1432017-05-19 10:43:36 +0530191
192} // namespace sel
193
194} // namespace ipmi