blob: ace17d83c8bac168e203afd3a89ae8bd94da9c4d [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;
Patrick Williams39deff22024-12-11 21:12:59 -050039using AdditionalData = std::map<std::string, std::string>;
40using 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
Lei YUaf378fa2020-12-02 16:28:57 +080060constexpr size_t SELRecordLength = 16;
61
62/** @struct SELEventRecord
Tom Joseph6b7a1432017-05-19 10:43:36 +053063 *
Lei YUaf378fa2020-12-02 16:28:57 +080064 * IPMI SEL Event Record
Tom Joseph6b7a1432017-05-19 10:43:36 +053065 */
Lei YUaf378fa2020-12-02 16:28:57 +080066struct SELEventRecord
Tom Joseph6b7a1432017-05-19 10:43:36 +053067{
Patrick Venture0b02be92018-08-31 11:55:55 -070068 uint16_t recordID; //!< Record ID.
69 uint8_t recordType; //!< Record Type.
70 uint32_t timeStamp; //!< Timestamp.
71 uint16_t generatorID; //!< Generator ID.
72 uint8_t eventMsgRevision; //!< Event Message Revision.
73 uint8_t sensorType; //!< Sensor Type.
74 uint8_t sensorNum; //!< Sensor Number.
75 uint8_t eventType; //!< Event Dir | Event Type.
76 uint8_t eventData1; //!< Event Data 1.
77 uint8_t eventData2; //!< Event Data 2.
78 uint8_t eventData3; //!< Event Data 3.
Tom Joseph6b7a1432017-05-19 10:43:36 +053079} __attribute__((packed));
80
Lei YUaf378fa2020-12-02 16:28:57 +080081static_assert(sizeof(SELEventRecord) == SELRecordLength);
82
83/** @struct SELOEMRecordTypeCD
84 *
85 * IPMI SEL OEM Record - Type C0h-DFh
86 */
87struct SELOEMRecordTypeCD
88{
89 uint16_t recordID; //!< Record ID.
90 uint8_t recordType; //!< Record Type.
91 uint32_t timeStamp; //!< Timestamp.
92 uint8_t manufacturerID[3]; //!< Manufacturer ID.
93 uint8_t oemDefined[6]; //!< OEM Defined data.
94} __attribute__((packed));
95
96static_assert(sizeof(SELOEMRecordTypeCD) == SELRecordLength);
97
98/** @struct SELOEMRecordTypeEF
99 *
100 * IPMI SEL OEM Record - Type E0h-FFh
101 */
102struct SELOEMRecordTypeEF
103{
104 uint16_t recordID; //!< Record ID.
105 uint8_t recordType; //!< Record Type.
106 uint8_t oemDefined[13]; //!< OEM Defined data.
107} __attribute__((packed));
108
109static_assert(sizeof(SELOEMRecordTypeEF) == SELRecordLength);
110
111union SELEventRecordFormat
112{
113 SELEventRecord eventRecord;
114 SELOEMRecordTypeCD oemCD;
115 SELOEMRecordTypeEF oemEF;
116};
117
118/** @struct GetSELEntryResponse
119 *
120 * IPMI payload for Get SEL Entry command response.
121 */
122struct GetSELEntryResponse
123{
124 uint16_t nextRecordID; //!< Next RecordID.
125 SELEventRecordFormat event; // !< The Event Record.
126} __attribute__((packed));
127
128static_assert(sizeof(GetSELEntryResponse) ==
129 SELRecordLength + sizeof(uint16_t));
130
Tom Joseph2f05bb52017-06-30 19:14:49 +0530131static constexpr auto initiateErase = 0xAA;
132static constexpr auto getEraseStatus = 0x00;
133static constexpr auto eraseComplete = 0x01;
134
Tom Joseph6edc8a02017-06-30 18:52:56 +0530135/** @brief Convert logging entry to SEL
136 *
137 * @param[in] objPath - DBUS object path of the logging entry.
138 *
139 * @return On success return the response of Get SEL entry command.
140 */
141GetSELEntryResponse convertLogEntrytoSEL(const std::string& objPath);
142
Tom Joseph399fd922017-06-30 18:40:30 +0530143/** @brief Get the timestamp of the log entry
144 *
145 * @param[in] objPath - DBUS object path of the logging entry.
146 *
147 * @return On success return the timestamp of the log entry as number of
148 * seconds from epoch.
149 */
150std::chrono::seconds getEntryTimeStamp(const std::string& objPath);
Tom Joseph6edc8a02017-06-30 18:52:56 +0530151
Tom Joseph232f5292017-07-07 20:14:02 +0530152/** @brief Read the logging entry object paths
153 *
154 * This API would read the logging dbus logging entry object paths and sorting
155 * the filename in the numeric order. The paths is cleared before populating
156 * the object paths.
157 *
158 * @param[in,out] paths - sorted list of logging entry object paths.
159 *
160 * @note This function is invoked when the Get SEL Info command or the Delete
161 * SEL entry command is invoked. The Get SEL Entry command is preceded
162 * typically by Get SEL Info command, so readLoggingObjectPaths is not
163 * invoked before each Get SEL entry command.
164 */
165void readLoggingObjectPaths(ObjectPaths& paths);
166
Lotus Xu57d35572021-01-24 11:13:13 +0800167template <typename T>
168std::string toHexStr(const T& data)
169{
170 std::stringstream stream;
171 stream << std::hex << std::uppercase << std::setfill('0');
172 for (const auto& v : data)
173 {
174 stream << std::setw(2) << static_cast<int>(v);
175 }
176 return stream.str();
177}
Tom Joseph6b7a1432017-05-19 10:43:36 +0530178namespace internal
179{
180
181/** @brief Convert logging entry to SEL event record
182 *
183 * @param[in] objPath - DBUS object path of the logging entry.
184 * @param[in] iter - Iterator to the sensor data corresponding to the logging
185 * entry
186 *
187 * @return On success return the SEL event record, throw an exception in case
188 * of failure.
189 */
Patrick Williams69b4c282025-03-03 11:19:13 -0500190GetSELEntryResponse prepareSELEntry(
191 const std::string& objPath,
192 ipmi::sensor::InvObjectIDMap::const_iterator iter);
Tom Joseph6b7a1432017-05-19 10:43:36 +0530193
Patrick Venture0b02be92018-08-31 11:55:55 -0700194} // namespace internal
Tom Joseph6b7a1432017-05-19 10:43:36 +0530195
196} // namespace sel
197
198} // namespace ipmi