blob: 91c4eaf2a47c8ad31a543a302c0a8361d718fbd2 [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
25static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
26
Tom Joseph232f5292017-07-07 20:14:02 +053027using ObjectPaths = std::vector<std::string>;
Tom Joseph306878b2017-07-10 19:30:54 +053028using PropertyName = std::string;
29using Resolved = bool;
30using Id = uint32_t;
31using Timestamp = uint64_t;
32using Message = std::string;
33using AdditionalData = std::vector<std::string>;
Vernon Mauery16b86932019-05-01 08:36:11 -070034using PropertyType =
35 std::variant<Resolved, Id, Timestamp, Message, AdditionalData>;
Tom Joseph6b7a1432017-05-19 10:43:36 +053036
Tom Joseph6f7deaa2017-06-30 19:03:54 +053037static constexpr auto selVersion = 0x51;
38static constexpr auto invalidTimeStamp = 0xFFFFFFFF;
Tom Joseph6f7deaa2017-06-30 19:03:54 +053039
Tom Josepha4953392017-06-30 19:09:47 +053040static constexpr auto firstEntry = 0x0000;
41static constexpr auto lastEntry = 0xFFFF;
42static constexpr auto entireRecord = 0xFF;
43static constexpr auto selRecordSize = 16;
44
jayaprakash Mutyalab7557722019-05-02 21:13:30 +000045namespace operationSupport
46{
47static constexpr bool overflow = false;
48static constexpr bool deleteSel = true;
49static constexpr bool partialAddSelEntry = false;
50static constexpr bool reserveSel = true;
51static constexpr bool getSelAllocationInfo = false;
52} // namespace operationSupport
53
Tom Josepha4953392017-06-30 19:09:47 +053054/** @struct GetSELEntryRequest
55 *
56 * IPMI payload for Get SEL Entry command request.
57 */
58struct GetSELEntryRequest
59{
Patrick Venture0b02be92018-08-31 11:55:55 -070060 uint16_t reservationID; //!< Reservation ID.
61 uint16_t selRecordID; //!< SEL Record ID.
62 uint8_t offset; //!< Offset into record.
63 uint8_t readLength; //!< Bytes to read.
Tom Josepha4953392017-06-30 19:09:47 +053064} __attribute__((packed));
65
Lei YUaf378fa2020-12-02 16:28:57 +080066constexpr size_t SELRecordLength = 16;
67
68/** @struct SELEventRecord
Tom Joseph6b7a1432017-05-19 10:43:36 +053069 *
Lei YUaf378fa2020-12-02 16:28:57 +080070 * IPMI SEL Event Record
Tom Joseph6b7a1432017-05-19 10:43:36 +053071 */
Lei YUaf378fa2020-12-02 16:28:57 +080072struct SELEventRecord
Tom Joseph6b7a1432017-05-19 10:43:36 +053073{
Patrick Venture0b02be92018-08-31 11:55:55 -070074 uint16_t recordID; //!< Record ID.
75 uint8_t recordType; //!< Record Type.
76 uint32_t timeStamp; //!< Timestamp.
77 uint16_t generatorID; //!< Generator ID.
78 uint8_t eventMsgRevision; //!< Event Message Revision.
79 uint8_t sensorType; //!< Sensor Type.
80 uint8_t sensorNum; //!< Sensor Number.
81 uint8_t eventType; //!< Event Dir | Event Type.
82 uint8_t eventData1; //!< Event Data 1.
83 uint8_t eventData2; //!< Event Data 2.
84 uint8_t eventData3; //!< Event Data 3.
Tom Joseph6b7a1432017-05-19 10:43:36 +053085} __attribute__((packed));
86
Lei YUaf378fa2020-12-02 16:28:57 +080087static_assert(sizeof(SELEventRecord) == SELRecordLength);
88
89/** @struct SELOEMRecordTypeCD
90 *
91 * IPMI SEL OEM Record - Type C0h-DFh
92 */
93struct SELOEMRecordTypeCD
94{
95 uint16_t recordID; //!< Record ID.
96 uint8_t recordType; //!< Record Type.
97 uint32_t timeStamp; //!< Timestamp.
98 uint8_t manufacturerID[3]; //!< Manufacturer ID.
99 uint8_t oemDefined[6]; //!< OEM Defined data.
100} __attribute__((packed));
101
102static_assert(sizeof(SELOEMRecordTypeCD) == SELRecordLength);
103
104/** @struct SELOEMRecordTypeEF
105 *
106 * IPMI SEL OEM Record - Type E0h-FFh
107 */
108struct SELOEMRecordTypeEF
109{
110 uint16_t recordID; //!< Record ID.
111 uint8_t recordType; //!< Record Type.
112 uint8_t oemDefined[13]; //!< OEM Defined data.
113} __attribute__((packed));
114
115static_assert(sizeof(SELOEMRecordTypeEF) == SELRecordLength);
116
117union SELEventRecordFormat
118{
119 SELEventRecord eventRecord;
120 SELOEMRecordTypeCD oemCD;
121 SELOEMRecordTypeEF oemEF;
122};
123
124/** @struct GetSELEntryResponse
125 *
126 * IPMI payload for Get SEL Entry command response.
127 */
128struct GetSELEntryResponse
129{
130 uint16_t nextRecordID; //!< Next RecordID.
131 SELEventRecordFormat event; // !< The Event Record.
132} __attribute__((packed));
133
134static_assert(sizeof(GetSELEntryResponse) ==
135 SELRecordLength + sizeof(uint16_t));
136
Tom Joseph2f05bb52017-06-30 19:14:49 +0530137static constexpr auto initiateErase = 0xAA;
138static constexpr auto getEraseStatus = 0x00;
139static constexpr auto eraseComplete = 0x01;
140
Tom Joseph6edc8a02017-06-30 18:52:56 +0530141/** @brief Convert logging entry to SEL
142 *
143 * @param[in] objPath - DBUS object path of the logging entry.
144 *
145 * @return On success return the response of Get SEL entry command.
146 */
147GetSELEntryResponse convertLogEntrytoSEL(const std::string& objPath);
148
Tom Joseph399fd922017-06-30 18:40:30 +0530149/** @brief Get the timestamp of the log entry
150 *
151 * @param[in] objPath - DBUS object path of the logging entry.
152 *
153 * @return On success return the timestamp of the log entry as number of
154 * seconds from epoch.
155 */
156std::chrono::seconds getEntryTimeStamp(const std::string& objPath);
Tom Joseph6edc8a02017-06-30 18:52:56 +0530157
Tom Joseph232f5292017-07-07 20:14:02 +0530158/** @brief Read the logging entry object paths
159 *
160 * This API would read the logging dbus logging entry object paths and sorting
161 * the filename in the numeric order. The paths is cleared before populating
162 * the object paths.
163 *
164 * @param[in,out] paths - sorted list of logging entry object paths.
165 *
166 * @note This function is invoked when the Get SEL Info command or the Delete
167 * SEL entry command is invoked. The Get SEL Entry command is preceded
168 * typically by Get SEL Info command, so readLoggingObjectPaths is not
169 * invoked before each Get SEL entry command.
170 */
171void readLoggingObjectPaths(ObjectPaths& paths);
172
Lotus Xu57d35572021-01-24 11:13:13 +0800173template <typename T>
174std::string toHexStr(const T& data)
175{
176 std::stringstream stream;
177 stream << std::hex << std::uppercase << std::setfill('0');
178 for (const auto& v : data)
179 {
180 stream << std::setw(2) << static_cast<int>(v);
181 }
182 return stream.str();
183}
Tom Joseph6b7a1432017-05-19 10:43:36 +0530184namespace internal
185{
186
187/** @brief Convert logging entry to SEL event record
188 *
189 * @param[in] objPath - DBUS object path of the logging entry.
190 * @param[in] iter - Iterator to the sensor data corresponding to the logging
191 * entry
192 *
193 * @return On success return the SEL event record, throw an exception in case
194 * of failure.
195 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700196GetSELEntryResponse
197 prepareSELEntry(const std::string& objPath,
198 ipmi::sensor::InvObjectIDMap::const_iterator iter);
Tom Joseph6b7a1432017-05-19 10:43:36 +0530199
Patrick Venture0b02be92018-08-31 11:55:55 -0700200} // namespace internal
Tom Joseph6b7a1432017-05-19 10:43:36 +0530201
202} // namespace sel
203
204} // namespace ipmi