blob: 3c9b098ed561e269350cf268a887cb2cfd2b16d2 [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
22static constexpr auto logBasePath = "/xyz/openbmc_project/logging/entry";
23static constexpr auto logEntryIntf = "xyz.openbmc_project.Logging.Entry";
24static constexpr auto logDeleteIntf = "xyz.openbmc_project.Object.Delete";
25
Lotus Xu78fe1b12021-05-23 17:26:56 +080026static constexpr auto logObj = "/xyz/openbmc_project/logging";
27static constexpr auto logIntf = "xyz.openbmc_project.Collection.DeleteAll";
28static constexpr auto logDeleteAllMethod = "DeleteAll";
29
Tom Joseph6b7a1432017-05-19 10:43:36 +053030static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
31
Tom Joseph232f5292017-07-07 20:14:02 +053032using ObjectPaths = std::vector<std::string>;
Tom Joseph306878b2017-07-10 19:30:54 +053033using PropertyName = std::string;
34using Resolved = bool;
35using Id = uint32_t;
36using Timestamp = uint64_t;
37using Message = std::string;
38using AdditionalData = std::vector<std::string>;
Vernon Mauery16b86932019-05-01 08:36:11 -070039using PropertyType =
40 std::variant<Resolved, Id, Timestamp, Message, AdditionalData>;
Tom Joseph6b7a1432017-05-19 10:43:36 +053041
Tom Joseph6f7deaa2017-06-30 19:03:54 +053042static constexpr auto selVersion = 0x51;
43static constexpr auto invalidTimeStamp = 0xFFFFFFFF;
Tom Joseph6f7deaa2017-06-30 19:03:54 +053044
Tom Josepha4953392017-06-30 19:09:47 +053045static constexpr auto firstEntry = 0x0000;
46static constexpr auto lastEntry = 0xFFFF;
47static constexpr auto entireRecord = 0xFF;
48static constexpr auto selRecordSize = 16;
49
jayaprakash Mutyalab7557722019-05-02 21:13:30 +000050namespace operationSupport
51{
52static constexpr bool overflow = false;
53static constexpr bool deleteSel = true;
54static constexpr bool partialAddSelEntry = false;
55static constexpr bool reserveSel = true;
56static constexpr bool getSelAllocationInfo = false;
57} // namespace operationSupport
58
Tom Josepha4953392017-06-30 19:09:47 +053059/** @struct GetSELEntryRequest
60 *
61 * IPMI payload for Get SEL Entry command request.
62 */
63struct GetSELEntryRequest
64{
Patrick Venture0b02be92018-08-31 11:55:55 -070065 uint16_t reservationID; //!< Reservation ID.
66 uint16_t selRecordID; //!< SEL Record ID.
67 uint8_t offset; //!< Offset into record.
68 uint8_t readLength; //!< Bytes to read.
Tom Josepha4953392017-06-30 19:09:47 +053069} __attribute__((packed));
70
Lei YUaf378fa2020-12-02 16:28:57 +080071constexpr size_t SELRecordLength = 16;
72
73/** @struct SELEventRecord
Tom Joseph6b7a1432017-05-19 10:43:36 +053074 *
Lei YUaf378fa2020-12-02 16:28:57 +080075 * IPMI SEL Event Record
Tom Joseph6b7a1432017-05-19 10:43:36 +053076 */
Lei YUaf378fa2020-12-02 16:28:57 +080077struct SELEventRecord
Tom Joseph6b7a1432017-05-19 10:43:36 +053078{
Patrick Venture0b02be92018-08-31 11:55:55 -070079 uint16_t recordID; //!< Record ID.
80 uint8_t recordType; //!< Record Type.
81 uint32_t timeStamp; //!< Timestamp.
82 uint16_t generatorID; //!< Generator ID.
83 uint8_t eventMsgRevision; //!< Event Message Revision.
84 uint8_t sensorType; //!< Sensor Type.
85 uint8_t sensorNum; //!< Sensor Number.
86 uint8_t eventType; //!< Event Dir | Event Type.
87 uint8_t eventData1; //!< Event Data 1.
88 uint8_t eventData2; //!< Event Data 2.
89 uint8_t eventData3; //!< Event Data 3.
Tom Joseph6b7a1432017-05-19 10:43:36 +053090} __attribute__((packed));
91
Lei YUaf378fa2020-12-02 16:28:57 +080092static_assert(sizeof(SELEventRecord) == SELRecordLength);
93
94/** @struct SELOEMRecordTypeCD
95 *
96 * IPMI SEL OEM Record - Type C0h-DFh
97 */
98struct SELOEMRecordTypeCD
99{
100 uint16_t recordID; //!< Record ID.
101 uint8_t recordType; //!< Record Type.
102 uint32_t timeStamp; //!< Timestamp.
103 uint8_t manufacturerID[3]; //!< Manufacturer ID.
104 uint8_t oemDefined[6]; //!< OEM Defined data.
105} __attribute__((packed));
106
107static_assert(sizeof(SELOEMRecordTypeCD) == SELRecordLength);
108
109/** @struct SELOEMRecordTypeEF
110 *
111 * IPMI SEL OEM Record - Type E0h-FFh
112 */
113struct SELOEMRecordTypeEF
114{
115 uint16_t recordID; //!< Record ID.
116 uint8_t recordType; //!< Record Type.
117 uint8_t oemDefined[13]; //!< OEM Defined data.
118} __attribute__((packed));
119
120static_assert(sizeof(SELOEMRecordTypeEF) == SELRecordLength);
121
122union SELEventRecordFormat
123{
124 SELEventRecord eventRecord;
125 SELOEMRecordTypeCD oemCD;
126 SELOEMRecordTypeEF oemEF;
127};
128
129/** @struct GetSELEntryResponse
130 *
131 * IPMI payload for Get SEL Entry command response.
132 */
133struct GetSELEntryResponse
134{
135 uint16_t nextRecordID; //!< Next RecordID.
136 SELEventRecordFormat event; // !< The Event Record.
137} __attribute__((packed));
138
139static_assert(sizeof(GetSELEntryResponse) ==
140 SELRecordLength + sizeof(uint16_t));
141
Tom Joseph2f05bb52017-06-30 19:14:49 +0530142static constexpr auto initiateErase = 0xAA;
143static constexpr auto getEraseStatus = 0x00;
144static constexpr auto eraseComplete = 0x01;
145
Tom Joseph6edc8a02017-06-30 18:52:56 +0530146/** @brief Convert logging entry to SEL
147 *
148 * @param[in] objPath - DBUS object path of the logging entry.
149 *
150 * @return On success return the response of Get SEL entry command.
151 */
152GetSELEntryResponse convertLogEntrytoSEL(const std::string& objPath);
153
Tom Joseph399fd922017-06-30 18:40:30 +0530154/** @brief Get the timestamp of the log entry
155 *
156 * @param[in] objPath - DBUS object path of the logging entry.
157 *
158 * @return On success return the timestamp of the log entry as number of
159 * seconds from epoch.
160 */
161std::chrono::seconds getEntryTimeStamp(const std::string& objPath);
Tom Joseph6edc8a02017-06-30 18:52:56 +0530162
Tom Joseph232f5292017-07-07 20:14:02 +0530163/** @brief Read the logging entry object paths
164 *
165 * This API would read the logging dbus logging entry object paths and sorting
166 * the filename in the numeric order. The paths is cleared before populating
167 * the object paths.
168 *
169 * @param[in,out] paths - sorted list of logging entry object paths.
170 *
171 * @note This function is invoked when the Get SEL Info command or the Delete
172 * SEL entry command is invoked. The Get SEL Entry command is preceded
173 * typically by Get SEL Info command, so readLoggingObjectPaths is not
174 * invoked before each Get SEL entry command.
175 */
176void readLoggingObjectPaths(ObjectPaths& paths);
177
Lotus Xu57d35572021-01-24 11:13:13 +0800178template <typename T>
179std::string toHexStr(const T& data)
180{
181 std::stringstream stream;
182 stream << std::hex << std::uppercase << std::setfill('0');
183 for (const auto& v : data)
184 {
185 stream << std::setw(2) << static_cast<int>(v);
186 }
187 return stream.str();
188}
Tom Joseph6b7a1432017-05-19 10:43:36 +0530189namespace internal
190{
191
192/** @brief Convert logging entry to SEL event record
193 *
194 * @param[in] objPath - DBUS object path of the logging entry.
195 * @param[in] iter - Iterator to the sensor data corresponding to the logging
196 * entry
197 *
198 * @return On success return the SEL event record, throw an exception in case
199 * of failure.
200 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700201GetSELEntryResponse
202 prepareSELEntry(const std::string& objPath,
203 ipmi::sensor::InvObjectIDMap::const_iterator iter);
Tom Joseph6b7a1432017-05-19 10:43:36 +0530204
Patrick Venture0b02be92018-08-31 11:55:55 -0700205} // namespace internal
Tom Joseph6b7a1432017-05-19 10:43:36 +0530206
207} // namespace sel
208
209} // namespace ipmi