blob: fa28fb19be381f58fa251cf43acc4fdf40b344eb [file] [log] [blame]
Tom Joseph6b7a1432017-05-19 10:43:36 +05301#pragma once
2
Yong Li021f2d12018-09-26 16:09:22 +08003#include <chrono>
Tom Joseph6b7a1432017-05-19 10:43:36 +05304#include <cstdint>
Lotus Xu57d35572021-01-24 11:13:13 +08005#include <iomanip>
6#include <iostream>
Vernon Mauery33250242019-03-12 16:49:26 -07007#include <ipmid/types.hpp>
Tom Joseph6b7a1432017-05-19 10:43:36 +05308#include <sdbusplus/server.hpp>
Lotus Xu57d35572021-01-24 11:13:13 +08009#include <sstream>
Tom Joseph6b7a1432017-05-19 10:43:36 +053010
11namespace ipmi
12{
13
14namespace sel
15{
16
17static constexpr auto mapperBusName = "xyz.openbmc_project.ObjectMapper";
18static constexpr auto mapperObjPath = "/xyz/openbmc_project/object_mapper";
19static constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper";
20
21static constexpr auto logBasePath = "/xyz/openbmc_project/logging/entry";
22static constexpr auto logEntryIntf = "xyz.openbmc_project.Logging.Entry";
23static constexpr auto logDeleteIntf = "xyz.openbmc_project.Object.Delete";
24
Lotus Xu78fe1b12021-05-23 17:26:56 +080025static constexpr auto logObj = "/xyz/openbmc_project/logging";
26static constexpr auto logIntf = "xyz.openbmc_project.Collection.DeleteAll";
27static constexpr auto logDeleteAllMethod = "DeleteAll";
28
Tom Joseph6b7a1432017-05-19 10:43:36 +053029static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
30
Tom Joseph232f5292017-07-07 20:14:02 +053031using ObjectPaths = std::vector<std::string>;
Tom Joseph306878b2017-07-10 19:30:54 +053032using PropertyName = std::string;
33using Resolved = bool;
34using Id = uint32_t;
35using Timestamp = uint64_t;
36using Message = std::string;
37using AdditionalData = std::vector<std::string>;
Vernon Mauery16b86932019-05-01 08:36:11 -070038using PropertyType =
39 std::variant<Resolved, Id, Timestamp, Message, AdditionalData>;
Tom Joseph6b7a1432017-05-19 10:43:36 +053040
Tom Joseph6f7deaa2017-06-30 19:03:54 +053041static constexpr auto selVersion = 0x51;
42static constexpr auto invalidTimeStamp = 0xFFFFFFFF;
Tom Joseph6f7deaa2017-06-30 19:03:54 +053043
Tom Josepha4953392017-06-30 19:09:47 +053044static constexpr auto firstEntry = 0x0000;
45static constexpr auto lastEntry = 0xFFFF;
46static constexpr auto entireRecord = 0xFF;
47static constexpr auto selRecordSize = 16;
48
jayaprakash Mutyalab7557722019-05-02 21:13:30 +000049namespace operationSupport
50{
51static constexpr bool overflow = false;
52static constexpr bool deleteSel = true;
53static constexpr bool partialAddSelEntry = false;
54static constexpr bool reserveSel = true;
55static constexpr bool getSelAllocationInfo = false;
56} // namespace operationSupport
57
Tom Josepha4953392017-06-30 19:09:47 +053058/** @struct GetSELEntryRequest
59 *
60 * IPMI payload for Get SEL Entry command request.
61 */
62struct GetSELEntryRequest
63{
Patrick Venture0b02be92018-08-31 11:55:55 -070064 uint16_t reservationID; //!< Reservation ID.
65 uint16_t selRecordID; //!< SEL Record ID.
66 uint8_t offset; //!< Offset into record.
67 uint8_t readLength; //!< Bytes to read.
Tom Josepha4953392017-06-30 19:09:47 +053068} __attribute__((packed));
69
Lei YUaf378fa2020-12-02 16:28:57 +080070constexpr size_t SELRecordLength = 16;
71
72/** @struct SELEventRecord
Tom Joseph6b7a1432017-05-19 10:43:36 +053073 *
Lei YUaf378fa2020-12-02 16:28:57 +080074 * IPMI SEL Event Record
Tom Joseph6b7a1432017-05-19 10:43:36 +053075 */
Lei YUaf378fa2020-12-02 16:28:57 +080076struct SELEventRecord
Tom Joseph6b7a1432017-05-19 10:43:36 +053077{
Patrick Venture0b02be92018-08-31 11:55:55 -070078 uint16_t recordID; //!< Record ID.
79 uint8_t recordType; //!< Record Type.
80 uint32_t timeStamp; //!< Timestamp.
81 uint16_t generatorID; //!< Generator ID.
82 uint8_t eventMsgRevision; //!< Event Message Revision.
83 uint8_t sensorType; //!< Sensor Type.
84 uint8_t sensorNum; //!< Sensor Number.
85 uint8_t eventType; //!< Event Dir | Event Type.
86 uint8_t eventData1; //!< Event Data 1.
87 uint8_t eventData2; //!< Event Data 2.
88 uint8_t eventData3; //!< Event Data 3.
Tom Joseph6b7a1432017-05-19 10:43:36 +053089} __attribute__((packed));
90
Lei YUaf378fa2020-12-02 16:28:57 +080091static_assert(sizeof(SELEventRecord) == SELRecordLength);
92
93/** @struct SELOEMRecordTypeCD
94 *
95 * IPMI SEL OEM Record - Type C0h-DFh
96 */
97struct SELOEMRecordTypeCD
98{
99 uint16_t recordID; //!< Record ID.
100 uint8_t recordType; //!< Record Type.
101 uint32_t timeStamp; //!< Timestamp.
102 uint8_t manufacturerID[3]; //!< Manufacturer ID.
103 uint8_t oemDefined[6]; //!< OEM Defined data.
104} __attribute__((packed));
105
106static_assert(sizeof(SELOEMRecordTypeCD) == SELRecordLength);
107
108/** @struct SELOEMRecordTypeEF
109 *
110 * IPMI SEL OEM Record - Type E0h-FFh
111 */
112struct SELOEMRecordTypeEF
113{
114 uint16_t recordID; //!< Record ID.
115 uint8_t recordType; //!< Record Type.
116 uint8_t oemDefined[13]; //!< OEM Defined data.
117} __attribute__((packed));
118
119static_assert(sizeof(SELOEMRecordTypeEF) == SELRecordLength);
120
121union SELEventRecordFormat
122{
123 SELEventRecord eventRecord;
124 SELOEMRecordTypeCD oemCD;
125 SELOEMRecordTypeEF oemEF;
126};
127
128/** @struct GetSELEntryResponse
129 *
130 * IPMI payload for Get SEL Entry command response.
131 */
132struct GetSELEntryResponse
133{
134 uint16_t nextRecordID; //!< Next RecordID.
135 SELEventRecordFormat event; // !< The Event Record.
136} __attribute__((packed));
137
138static_assert(sizeof(GetSELEntryResponse) ==
139 SELRecordLength + sizeof(uint16_t));
140
Tom Joseph2f05bb52017-06-30 19:14:49 +0530141static constexpr auto initiateErase = 0xAA;
142static constexpr auto getEraseStatus = 0x00;
143static constexpr auto eraseComplete = 0x01;
144
Tom Joseph6edc8a02017-06-30 18:52:56 +0530145/** @brief Convert logging entry to SEL
146 *
147 * @param[in] objPath - DBUS object path of the logging entry.
148 *
149 * @return On success return the response of Get SEL entry command.
150 */
151GetSELEntryResponse convertLogEntrytoSEL(const std::string& objPath);
152
Tom Joseph399fd922017-06-30 18:40:30 +0530153/** @brief Get the timestamp of the log entry
154 *
155 * @param[in] objPath - DBUS object path of the logging entry.
156 *
157 * @return On success return the timestamp of the log entry as number of
158 * seconds from epoch.
159 */
160std::chrono::seconds getEntryTimeStamp(const std::string& objPath);
Tom Joseph6edc8a02017-06-30 18:52:56 +0530161
Tom Joseph232f5292017-07-07 20:14:02 +0530162/** @brief Read the logging entry object paths
163 *
164 * This API would read the logging dbus logging entry object paths and sorting
165 * the filename in the numeric order. The paths is cleared before populating
166 * the object paths.
167 *
168 * @param[in,out] paths - sorted list of logging entry object paths.
169 *
170 * @note This function is invoked when the Get SEL Info command or the Delete
171 * SEL entry command is invoked. The Get SEL Entry command is preceded
172 * typically by Get SEL Info command, so readLoggingObjectPaths is not
173 * invoked before each Get SEL entry command.
174 */
175void readLoggingObjectPaths(ObjectPaths& paths);
176
Lotus Xu57d35572021-01-24 11:13:13 +0800177template <typename T>
178std::string toHexStr(const T& data)
179{
180 std::stringstream stream;
181 stream << std::hex << std::uppercase << std::setfill('0');
182 for (const auto& v : data)
183 {
184 stream << std::setw(2) << static_cast<int>(v);
185 }
186 return stream.str();
187}
Tom Joseph6b7a1432017-05-19 10:43:36 +0530188namespace internal
189{
190
191/** @brief Convert logging entry to SEL event record
192 *
193 * @param[in] objPath - DBUS object path of the logging entry.
194 * @param[in] iter - Iterator to the sensor data corresponding to the logging
195 * entry
196 *
197 * @return On success return the SEL event record, throw an exception in case
198 * of failure.
199 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700200GetSELEntryResponse
201 prepareSELEntry(const std::string& objPath,
202 ipmi::sensor::InvObjectIDMap::const_iterator iter);
Tom Joseph6b7a1432017-05-19 10:43:36 +0530203
Patrick Venture0b02be92018-08-31 11:55:55 -0700204} // namespace internal
Tom Joseph6b7a1432017-05-19 10:43:36 +0530205
206} // namespace sel
207
208} // namespace ipmi