blob: 29f925a42da99211958c7abed25d4f99ede7fb42 [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>;
Vernon Mauery16b86932019-05-01 08:36:11 -070040using PropertyType =
41 std::variant<Resolved, Id, Timestamp, Message, AdditionalData>;
Tom Joseph6b7a1432017-05-19 10:43:36 +053042
Tom Joseph6f7deaa2017-06-30 19:03:54 +053043static constexpr auto selVersion = 0x51;
44static constexpr auto invalidTimeStamp = 0xFFFFFFFF;
Tom Joseph6f7deaa2017-06-30 19:03:54 +053045
Tom Josepha4953392017-06-30 19:09:47 +053046static constexpr auto firstEntry = 0x0000;
47static constexpr auto lastEntry = 0xFFFF;
48static constexpr auto entireRecord = 0xFF;
49static constexpr auto selRecordSize = 16;
50
jayaprakash Mutyalab7557722019-05-02 21:13:30 +000051namespace operationSupport
52{
53static constexpr bool overflow = false;
54static constexpr bool deleteSel = true;
55static constexpr bool partialAddSelEntry = false;
56static constexpr bool reserveSel = true;
57static constexpr bool getSelAllocationInfo = false;
58} // namespace operationSupport
59
Tom Josepha4953392017-06-30 19:09:47 +053060/** @struct GetSELEntryRequest
61 *
62 * IPMI payload for Get SEL Entry command request.
63 */
64struct GetSELEntryRequest
65{
Patrick Venture0b02be92018-08-31 11:55:55 -070066 uint16_t reservationID; //!< Reservation ID.
67 uint16_t selRecordID; //!< SEL Record ID.
68 uint8_t offset; //!< Offset into record.
69 uint8_t readLength; //!< Bytes to read.
Tom Josepha4953392017-06-30 19:09:47 +053070} __attribute__((packed));
71
Lei YUaf378fa2020-12-02 16:28:57 +080072constexpr size_t SELRecordLength = 16;
73
74/** @struct SELEventRecord
Tom Joseph6b7a1432017-05-19 10:43:36 +053075 *
Lei YUaf378fa2020-12-02 16:28:57 +080076 * IPMI SEL Event Record
Tom Joseph6b7a1432017-05-19 10:43:36 +053077 */
Lei YUaf378fa2020-12-02 16:28:57 +080078struct SELEventRecord
Tom Joseph6b7a1432017-05-19 10:43:36 +053079{
Patrick Venture0b02be92018-08-31 11:55:55 -070080 uint16_t recordID; //!< Record ID.
81 uint8_t recordType; //!< Record Type.
82 uint32_t timeStamp; //!< Timestamp.
83 uint16_t generatorID; //!< Generator ID.
84 uint8_t eventMsgRevision; //!< Event Message Revision.
85 uint8_t sensorType; //!< Sensor Type.
86 uint8_t sensorNum; //!< Sensor Number.
87 uint8_t eventType; //!< Event Dir | Event Type.
88 uint8_t eventData1; //!< Event Data 1.
89 uint8_t eventData2; //!< Event Data 2.
90 uint8_t eventData3; //!< Event Data 3.
Tom Joseph6b7a1432017-05-19 10:43:36 +053091} __attribute__((packed));
92
Lei YUaf378fa2020-12-02 16:28:57 +080093static_assert(sizeof(SELEventRecord) == SELRecordLength);
94
95/** @struct SELOEMRecordTypeCD
96 *
97 * IPMI SEL OEM Record - Type C0h-DFh
98 */
99struct SELOEMRecordTypeCD
100{
101 uint16_t recordID; //!< Record ID.
102 uint8_t recordType; //!< Record Type.
103 uint32_t timeStamp; //!< Timestamp.
104 uint8_t manufacturerID[3]; //!< Manufacturer ID.
105 uint8_t oemDefined[6]; //!< OEM Defined data.
106} __attribute__((packed));
107
108static_assert(sizeof(SELOEMRecordTypeCD) == SELRecordLength);
109
110/** @struct SELOEMRecordTypeEF
111 *
112 * IPMI SEL OEM Record - Type E0h-FFh
113 */
114struct SELOEMRecordTypeEF
115{
116 uint16_t recordID; //!< Record ID.
117 uint8_t recordType; //!< Record Type.
118 uint8_t oemDefined[13]; //!< OEM Defined data.
119} __attribute__((packed));
120
121static_assert(sizeof(SELOEMRecordTypeEF) == SELRecordLength);
122
123union SELEventRecordFormat
124{
125 SELEventRecord eventRecord;
126 SELOEMRecordTypeCD oemCD;
127 SELOEMRecordTypeEF oemEF;
128};
129
130/** @struct GetSELEntryResponse
131 *
132 * IPMI payload for Get SEL Entry command response.
133 */
134struct GetSELEntryResponse
135{
136 uint16_t nextRecordID; //!< Next RecordID.
137 SELEventRecordFormat event; // !< The Event Record.
138} __attribute__((packed));
139
140static_assert(sizeof(GetSELEntryResponse) ==
141 SELRecordLength + sizeof(uint16_t));
142
Tom Joseph2f05bb52017-06-30 19:14:49 +0530143static constexpr auto initiateErase = 0xAA;
144static constexpr auto getEraseStatus = 0x00;
145static constexpr auto eraseComplete = 0x01;
146
Tom Joseph6edc8a02017-06-30 18:52:56 +0530147/** @brief Convert logging entry to SEL
148 *
149 * @param[in] objPath - DBUS object path of the logging entry.
150 *
151 * @return On success return the response of Get SEL entry command.
152 */
153GetSELEntryResponse convertLogEntrytoSEL(const std::string& objPath);
154
Tom Joseph399fd922017-06-30 18:40:30 +0530155/** @brief Get the timestamp of the log entry
156 *
157 * @param[in] objPath - DBUS object path of the logging entry.
158 *
159 * @return On success return the timestamp of the log entry as number of
160 * seconds from epoch.
161 */
162std::chrono::seconds getEntryTimeStamp(const std::string& objPath);
Tom Joseph6edc8a02017-06-30 18:52:56 +0530163
Tom Joseph232f5292017-07-07 20:14:02 +0530164/** @brief Read the logging entry object paths
165 *
166 * This API would read the logging dbus logging entry object paths and sorting
167 * the filename in the numeric order. The paths is cleared before populating
168 * the object paths.
169 *
170 * @param[in,out] paths - sorted list of logging entry object paths.
171 *
172 * @note This function is invoked when the Get SEL Info command or the Delete
173 * SEL entry command is invoked. The Get SEL Entry command is preceded
174 * typically by Get SEL Info command, so readLoggingObjectPaths is not
175 * invoked before each Get SEL entry command.
176 */
177void readLoggingObjectPaths(ObjectPaths& paths);
178
Lotus Xu57d35572021-01-24 11:13:13 +0800179template <typename T>
180std::string toHexStr(const T& data)
181{
182 std::stringstream stream;
183 stream << std::hex << std::uppercase << std::setfill('0');
184 for (const auto& v : data)
185 {
186 stream << std::setw(2) << static_cast<int>(v);
187 }
188 return stream.str();
189}
Tom Joseph6b7a1432017-05-19 10:43:36 +0530190namespace internal
191{
192
193/** @brief Convert logging entry to SEL event record
194 *
195 * @param[in] objPath - DBUS object path of the logging entry.
196 * @param[in] iter - Iterator to the sensor data corresponding to the logging
197 * entry
198 *
199 * @return On success return the SEL event record, throw an exception in case
200 * of failure.
201 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700202GetSELEntryResponse
203 prepareSELEntry(const std::string& objPath,
204 ipmi::sensor::InvObjectIDMap::const_iterator iter);
Tom Joseph6b7a1432017-05-19 10:43:36 +0530205
Patrick Venture0b02be92018-08-31 11:55:55 -0700206} // namespace internal
Tom Joseph6b7a1432017-05-19 10:43:36 +0530207
208} // namespace sel
209
210} // namespace ipmi