blob: 8c51c54febe757f91d970126ce5aadded34bee57 [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
18static constexpr auto mapperBusName = "xyz.openbmc_project.ObjectMapper";
19static constexpr auto mapperObjPath = "/xyz/openbmc_project/object_mapper";
20static constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper";
21
George Liu656ae3c2024-08-23 16:44:22 +080022static constexpr auto logWatchPath = "/xyz/openbmc_project/logging";
Tom Joseph6b7a1432017-05-19 10:43:36 +053023static constexpr auto logBasePath = "/xyz/openbmc_project/logging/entry";
24static constexpr auto logEntryIntf = "xyz.openbmc_project.Logging.Entry";
25static constexpr auto logDeleteIntf = "xyz.openbmc_project.Object.Delete";
26
Lotus Xu78fe1b12021-05-23 17:26:56 +080027static constexpr auto logObj = "/xyz/openbmc_project/logging";
28static constexpr auto logIntf = "xyz.openbmc_project.Collection.DeleteAll";
29static constexpr auto logDeleteAllMethod = "DeleteAll";
30
Tom Joseph6b7a1432017-05-19 10:43:36 +053031static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
32
Tom Joseph232f5292017-07-07 20:14:02 +053033using ObjectPaths = std::vector<std::string>;
Tom Joseph306878b2017-07-10 19:30:54 +053034using PropertyName = std::string;
35using Resolved = bool;
36using Id = uint32_t;
37using Timestamp = uint64_t;
38using Message = std::string;
39using AdditionalData = std::vector<std::string>;
Patrick Williamsbe5a2e02024-11-22 11:23:17 -050040using AdditionalData2 = std::map<std::string, std::string>;
41using PropertyType = std::variant<Resolved, Id, Timestamp, Message,
42 AdditionalData, AdditionalData2>;
Tom Joseph6b7a1432017-05-19 10:43:36 +053043
Tom Joseph6f7deaa2017-06-30 19:03:54 +053044static constexpr auto selVersion = 0x51;
45static constexpr auto invalidTimeStamp = 0xFFFFFFFF;
Tom Joseph6f7deaa2017-06-30 19:03:54 +053046
Tom Josepha4953392017-06-30 19:09:47 +053047static constexpr auto firstEntry = 0x0000;
48static constexpr auto lastEntry = 0xFFFF;
49static constexpr auto entireRecord = 0xFF;
50static constexpr auto selRecordSize = 16;
51
jayaprakash Mutyalab7557722019-05-02 21:13:30 +000052namespace operationSupport
53{
54static constexpr bool overflow = false;
55static constexpr bool deleteSel = true;
56static constexpr bool partialAddSelEntry = false;
57static constexpr bool reserveSel = true;
58static constexpr bool getSelAllocationInfo = false;
59} // namespace operationSupport
60
Tom Josepha4953392017-06-30 19:09:47 +053061/** @struct GetSELEntryRequest
62 *
63 * IPMI payload for Get SEL Entry command request.
64 */
65struct GetSELEntryRequest
66{
Patrick Venture0b02be92018-08-31 11:55:55 -070067 uint16_t reservationID; //!< Reservation ID.
68 uint16_t selRecordID; //!< SEL Record ID.
69 uint8_t offset; //!< Offset into record.
70 uint8_t readLength; //!< Bytes to read.
Tom Josepha4953392017-06-30 19:09:47 +053071} __attribute__((packed));
72
Lei YUaf378fa2020-12-02 16:28:57 +080073constexpr size_t SELRecordLength = 16;
74
75/** @struct SELEventRecord
Tom Joseph6b7a1432017-05-19 10:43:36 +053076 *
Lei YUaf378fa2020-12-02 16:28:57 +080077 * IPMI SEL Event Record
Tom Joseph6b7a1432017-05-19 10:43:36 +053078 */
Lei YUaf378fa2020-12-02 16:28:57 +080079struct SELEventRecord
Tom Joseph6b7a1432017-05-19 10:43:36 +053080{
Patrick Venture0b02be92018-08-31 11:55:55 -070081 uint16_t recordID; //!< Record ID.
82 uint8_t recordType; //!< Record Type.
83 uint32_t timeStamp; //!< Timestamp.
84 uint16_t generatorID; //!< Generator ID.
85 uint8_t eventMsgRevision; //!< Event Message Revision.
86 uint8_t sensorType; //!< Sensor Type.
87 uint8_t sensorNum; //!< Sensor Number.
88 uint8_t eventType; //!< Event Dir | Event Type.
89 uint8_t eventData1; //!< Event Data 1.
90 uint8_t eventData2; //!< Event Data 2.
91 uint8_t eventData3; //!< Event Data 3.
Tom Joseph6b7a1432017-05-19 10:43:36 +053092} __attribute__((packed));
93
Lei YUaf378fa2020-12-02 16:28:57 +080094static_assert(sizeof(SELEventRecord) == SELRecordLength);
95
96/** @struct SELOEMRecordTypeCD
97 *
98 * IPMI SEL OEM Record - Type C0h-DFh
99 */
100struct SELOEMRecordTypeCD
101{
102 uint16_t recordID; //!< Record ID.
103 uint8_t recordType; //!< Record Type.
104 uint32_t timeStamp; //!< Timestamp.
105 uint8_t manufacturerID[3]; //!< Manufacturer ID.
106 uint8_t oemDefined[6]; //!< OEM Defined data.
107} __attribute__((packed));
108
109static_assert(sizeof(SELOEMRecordTypeCD) == SELRecordLength);
110
111/** @struct SELOEMRecordTypeEF
112 *
113 * IPMI SEL OEM Record - Type E0h-FFh
114 */
115struct SELOEMRecordTypeEF
116{
117 uint16_t recordID; //!< Record ID.
118 uint8_t recordType; //!< Record Type.
119 uint8_t oemDefined[13]; //!< OEM Defined data.
120} __attribute__((packed));
121
122static_assert(sizeof(SELOEMRecordTypeEF) == SELRecordLength);
123
124union SELEventRecordFormat
125{
126 SELEventRecord eventRecord;
127 SELOEMRecordTypeCD oemCD;
128 SELOEMRecordTypeEF oemEF;
129};
130
131/** @struct GetSELEntryResponse
132 *
133 * IPMI payload for Get SEL Entry command response.
134 */
135struct GetSELEntryResponse
136{
137 uint16_t nextRecordID; //!< Next RecordID.
138 SELEventRecordFormat event; // !< The Event Record.
139} __attribute__((packed));
140
141static_assert(sizeof(GetSELEntryResponse) ==
142 SELRecordLength + sizeof(uint16_t));
143
Tom Joseph2f05bb52017-06-30 19:14:49 +0530144static constexpr auto initiateErase = 0xAA;
145static constexpr auto getEraseStatus = 0x00;
146static constexpr auto eraseComplete = 0x01;
147
Tom Joseph6edc8a02017-06-30 18:52:56 +0530148/** @brief Convert logging entry to SEL
149 *
150 * @param[in] objPath - DBUS object path of the logging entry.
151 *
152 * @return On success return the response of Get SEL entry command.
153 */
154GetSELEntryResponse convertLogEntrytoSEL(const std::string& objPath);
155
Tom Joseph399fd922017-06-30 18:40:30 +0530156/** @brief Get the timestamp of the log entry
157 *
158 * @param[in] objPath - DBUS object path of the logging entry.
159 *
160 * @return On success return the timestamp of the log entry as number of
161 * seconds from epoch.
162 */
163std::chrono::seconds getEntryTimeStamp(const std::string& objPath);
Tom Joseph6edc8a02017-06-30 18:52:56 +0530164
Tom Joseph232f5292017-07-07 20:14:02 +0530165/** @brief Read the logging entry object paths
166 *
167 * This API would read the logging dbus logging entry object paths and sorting
168 * the filename in the numeric order. The paths is cleared before populating
169 * the object paths.
170 *
171 * @param[in,out] paths - sorted list of logging entry object paths.
172 *
173 * @note This function is invoked when the Get SEL Info command or the Delete
174 * SEL entry command is invoked. The Get SEL Entry command is preceded
175 * typically by Get SEL Info command, so readLoggingObjectPaths is not
176 * invoked before each Get SEL entry command.
177 */
178void readLoggingObjectPaths(ObjectPaths& paths);
179
Lotus Xu57d35572021-01-24 11:13:13 +0800180template <typename T>
181std::string toHexStr(const T& data)
182{
183 std::stringstream stream;
184 stream << std::hex << std::uppercase << std::setfill('0');
185 for (const auto& v : data)
186 {
187 stream << std::setw(2) << static_cast<int>(v);
188 }
189 return stream.str();
190}
Tom Joseph6b7a1432017-05-19 10:43:36 +0530191namespace internal
192{
193
194/** @brief Convert logging entry to SEL event record
195 *
196 * @param[in] objPath - DBUS object path of the logging entry.
197 * @param[in] iter - Iterator to the sensor data corresponding to the logging
198 * entry
199 *
200 * @return On success return the SEL event record, throw an exception in case
201 * of failure.
202 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700203GetSELEntryResponse
204 prepareSELEntry(const std::string& objPath,
205 ipmi::sensor::InvObjectIDMap::const_iterator iter);
Tom Joseph6b7a1432017-05-19 10:43:36 +0530206
Patrick Venture0b02be92018-08-31 11:55:55 -0700207} // namespace internal
Tom Joseph6b7a1432017-05-19 10:43:36 +0530208
209} // namespace sel
210
211} // namespace ipmi