blob: 06fc453e40a90e6fbcee95afc8fca2816b778fa1 [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>
Vernon Mauery33250242019-03-12 16:49:26 -07005#include <ipmid/types.hpp>
Tom Joseph6b7a1432017-05-19 10:43:36 +05306#include <sdbusplus/server.hpp>
Tom Joseph6b7a1432017-05-19 10:43:36 +05307
8namespace ipmi
9{
10
11namespace sel
12{
13
14static constexpr auto mapperBusName = "xyz.openbmc_project.ObjectMapper";
15static constexpr auto mapperObjPath = "/xyz/openbmc_project/object_mapper";
16static constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper";
17
18static constexpr auto logBasePath = "/xyz/openbmc_project/logging/entry";
19static constexpr auto logEntryIntf = "xyz.openbmc_project.Logging.Entry";
20static constexpr auto logDeleteIntf = "xyz.openbmc_project.Object.Delete";
21
22static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
23
Tom Joseph232f5292017-07-07 20:14:02 +053024using ObjectPaths = std::vector<std::string>;
Tom Joseph306878b2017-07-10 19:30:54 +053025using PropertyName = std::string;
26using Resolved = bool;
27using Id = uint32_t;
28using Timestamp = uint64_t;
29using Message = std::string;
30using AdditionalData = std::vector<std::string>;
Vernon Mauery16b86932019-05-01 08:36:11 -070031using PropertyType =
32 std::variant<Resolved, Id, Timestamp, Message, AdditionalData>;
Tom Joseph6b7a1432017-05-19 10:43:36 +053033
Tom Joseph6f7deaa2017-06-30 19:03:54 +053034static constexpr auto selVersion = 0x51;
35static constexpr auto invalidTimeStamp = 0xFFFFFFFF;
Tom Joseph6f7deaa2017-06-30 19:03:54 +053036
Tom Josepha4953392017-06-30 19:09:47 +053037static constexpr auto firstEntry = 0x0000;
38static constexpr auto lastEntry = 0xFFFF;
39static constexpr auto entireRecord = 0xFF;
40static constexpr auto selRecordSize = 16;
41
jayaprakash Mutyalab7557722019-05-02 21:13:30 +000042namespace operationSupport
43{
44static constexpr bool overflow = false;
45static constexpr bool deleteSel = true;
46static constexpr bool partialAddSelEntry = false;
47static constexpr bool reserveSel = true;
48static constexpr bool getSelAllocationInfo = false;
49} // namespace operationSupport
50
Tom Josepha4953392017-06-30 19:09:47 +053051/** @struct GetSELEntryRequest
52 *
53 * IPMI payload for Get SEL Entry command request.
54 */
55struct GetSELEntryRequest
56{
Patrick Venture0b02be92018-08-31 11:55:55 -070057 uint16_t reservationID; //!< Reservation ID.
58 uint16_t selRecordID; //!< SEL Record ID.
59 uint8_t offset; //!< Offset into record.
60 uint8_t readLength; //!< Bytes to read.
Tom Josepha4953392017-06-30 19:09:47 +053061} __attribute__((packed));
62
Lei YUaf378fa2020-12-02 16:28:57 +080063constexpr size_t SELRecordLength = 16;
64
65/** @struct SELEventRecord
Tom Joseph6b7a1432017-05-19 10:43:36 +053066 *
Lei YUaf378fa2020-12-02 16:28:57 +080067 * IPMI SEL Event Record
Tom Joseph6b7a1432017-05-19 10:43:36 +053068 */
Lei YUaf378fa2020-12-02 16:28:57 +080069struct SELEventRecord
Tom Joseph6b7a1432017-05-19 10:43:36 +053070{
Patrick Venture0b02be92018-08-31 11:55:55 -070071 uint16_t recordID; //!< Record ID.
72 uint8_t recordType; //!< Record Type.
73 uint32_t timeStamp; //!< Timestamp.
74 uint16_t generatorID; //!< Generator ID.
75 uint8_t eventMsgRevision; //!< Event Message Revision.
76 uint8_t sensorType; //!< Sensor Type.
77 uint8_t sensorNum; //!< Sensor Number.
78 uint8_t eventType; //!< Event Dir | Event Type.
79 uint8_t eventData1; //!< Event Data 1.
80 uint8_t eventData2; //!< Event Data 2.
81 uint8_t eventData3; //!< Event Data 3.
Tom Joseph6b7a1432017-05-19 10:43:36 +053082} __attribute__((packed));
83
Lei YUaf378fa2020-12-02 16:28:57 +080084static_assert(sizeof(SELEventRecord) == SELRecordLength);
85
86/** @struct SELOEMRecordTypeCD
87 *
88 * IPMI SEL OEM Record - Type C0h-DFh
89 */
90struct SELOEMRecordTypeCD
91{
92 uint16_t recordID; //!< Record ID.
93 uint8_t recordType; //!< Record Type.
94 uint32_t timeStamp; //!< Timestamp.
95 uint8_t manufacturerID[3]; //!< Manufacturer ID.
96 uint8_t oemDefined[6]; //!< OEM Defined data.
97} __attribute__((packed));
98
99static_assert(sizeof(SELOEMRecordTypeCD) == SELRecordLength);
100
101/** @struct SELOEMRecordTypeEF
102 *
103 * IPMI SEL OEM Record - Type E0h-FFh
104 */
105struct SELOEMRecordTypeEF
106{
107 uint16_t recordID; //!< Record ID.
108 uint8_t recordType; //!< Record Type.
109 uint8_t oemDefined[13]; //!< OEM Defined data.
110} __attribute__((packed));
111
112static_assert(sizeof(SELOEMRecordTypeEF) == SELRecordLength);
113
114union SELEventRecordFormat
115{
116 SELEventRecord eventRecord;
117 SELOEMRecordTypeCD oemCD;
118 SELOEMRecordTypeEF oemEF;
119};
120
121/** @struct GetSELEntryResponse
122 *
123 * IPMI payload for Get SEL Entry command response.
124 */
125struct GetSELEntryResponse
126{
127 uint16_t nextRecordID; //!< Next RecordID.
128 SELEventRecordFormat event; // !< The Event Record.
129} __attribute__((packed));
130
131static_assert(sizeof(GetSELEntryResponse) ==
132 SELRecordLength + sizeof(uint16_t));
133
Tom Joseph2f05bb52017-06-30 19:14:49 +0530134static constexpr auto initiateErase = 0xAA;
135static constexpr auto getEraseStatus = 0x00;
136static constexpr auto eraseComplete = 0x01;
137
Tom Joseph6edc8a02017-06-30 18:52:56 +0530138/** @brief Convert logging entry to SEL
139 *
140 * @param[in] objPath - DBUS object path of the logging entry.
141 *
142 * @return On success return the response of Get SEL entry command.
143 */
144GetSELEntryResponse convertLogEntrytoSEL(const std::string& objPath);
145
Tom Joseph399fd922017-06-30 18:40:30 +0530146/** @brief Get the timestamp of the log entry
147 *
148 * @param[in] objPath - DBUS object path of the logging entry.
149 *
150 * @return On success return the timestamp of the log entry as number of
151 * seconds from epoch.
152 */
153std::chrono::seconds getEntryTimeStamp(const std::string& objPath);
Tom Joseph6edc8a02017-06-30 18:52:56 +0530154
Tom Joseph232f5292017-07-07 20:14:02 +0530155/** @brief Read the logging entry object paths
156 *
157 * This API would read the logging dbus logging entry object paths and sorting
158 * the filename in the numeric order. The paths is cleared before populating
159 * the object paths.
160 *
161 * @param[in,out] paths - sorted list of logging entry object paths.
162 *
163 * @note This function is invoked when the Get SEL Info command or the Delete
164 * SEL entry command is invoked. The Get SEL Entry command is preceded
165 * typically by Get SEL Info command, so readLoggingObjectPaths is not
166 * invoked before each Get SEL entry command.
167 */
168void readLoggingObjectPaths(ObjectPaths& paths);
169
Tom Joseph6b7a1432017-05-19 10:43:36 +0530170namespace internal
171{
172
173/** @brief Convert logging entry to SEL event record
174 *
175 * @param[in] objPath - DBUS object path of the logging entry.
176 * @param[in] iter - Iterator to the sensor data corresponding to the logging
177 * entry
178 *
179 * @return On success return the SEL event record, throw an exception in case
180 * of failure.
181 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700182GetSELEntryResponse
183 prepareSELEntry(const std::string& objPath,
184 ipmi::sensor::InvObjectIDMap::const_iterator iter);
Tom Joseph6b7a1432017-05-19 10:43:36 +0530185
Patrick Venture0b02be92018-08-31 11:55:55 -0700186} // namespace internal
Tom Joseph6b7a1432017-05-19 10:43:36 +0530187
188} // namespace sel
189
190} // namespace ipmi