blob: 806f937244e6b4e0592070a67c29ec1d011e05b9 [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>;
31using PropertyType = sdbusplus::message::variant<Resolved, Id, Timestamp,
Patrick Venture0b02be92018-08-31 11:55:55 -070032 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;
36static constexpr auto operationSupport = 0x0A;
37
38/** @struct GetSELInfoResponse
39 *
40 * IPMI payload for Get SEL Info command response.
41 */
42struct GetSELInfoResponse
43{
Patrick Venture0b02be92018-08-31 11:55:55 -070044 uint8_t selVersion; //!< SEL revision.
45 uint16_t entries; //!< Number of log entries in SEL.
46 uint16_t freeSpace; //!< Free Space in bytes.
47 uint32_t addTimeStamp; //!< Most recent addition timestamp.
48 uint32_t eraseTimeStamp; //!< Most recent erase timestamp.
49 uint8_t operationSupport; //!< Operation support.
Tom Joseph6f7deaa2017-06-30 19:03:54 +053050} __attribute__((packed));
51
Tom Josepha4953392017-06-30 19:09:47 +053052static constexpr auto firstEntry = 0x0000;
53static constexpr auto lastEntry = 0xFFFF;
54static constexpr auto entireRecord = 0xFF;
55static constexpr auto selRecordSize = 16;
56
57/** @struct GetSELEntryRequest
58 *
59 * IPMI payload for Get SEL Entry command request.
60 */
61struct GetSELEntryRequest
62{
Patrick Venture0b02be92018-08-31 11:55:55 -070063 uint16_t reservationID; //!< Reservation ID.
64 uint16_t selRecordID; //!< SEL Record ID.
65 uint8_t offset; //!< Offset into record.
66 uint8_t readLength; //!< Bytes to read.
Tom Josepha4953392017-06-30 19:09:47 +053067} __attribute__((packed));
68
Tom Joseph6b7a1432017-05-19 10:43:36 +053069/** @struct GetSELEntryResponse
70 *
71 * IPMI payload for Get SEL Entry command response.
72 */
73struct GetSELEntryResponse
74{
Patrick Venture0b02be92018-08-31 11:55:55 -070075 uint16_t nextRecordID; //!< Next RecordID.
76 uint16_t recordID; //!< Record ID.
77 uint8_t recordType; //!< Record Type.
78 uint32_t timeStamp; //!< Timestamp.
79 uint16_t generatorID; //!< Generator ID.
80 uint8_t eventMsgRevision; //!< Event Message Revision.
81 uint8_t sensorType; //!< Sensor Type.
82 uint8_t sensorNum; //!< Sensor Number.
83 uint8_t eventType; //!< Event Dir | Event Type.
84 uint8_t eventData1; //!< Event Data 1.
85 uint8_t eventData2; //!< Event Data 2.
86 uint8_t eventData3; //!< Event Data 3.
Tom Joseph6b7a1432017-05-19 10:43:36 +053087} __attribute__((packed));
88
Tom Joseph8f4a2aa2017-06-30 19:12:49 +053089/** @struct DeleteSELEntryRequest
90 *
91 * IPMI payload for Delete SEL Entry command request.
92 */
93struct DeleteSELEntryRequest
94{
Patrick Venture0b02be92018-08-31 11:55:55 -070095 uint16_t reservationID; //!< Reservation ID.
96 uint16_t selRecordID; //!< SEL Record ID.
Tom Joseph8f4a2aa2017-06-30 19:12:49 +053097} __attribute__((packed));
98
Tom Joseph2f05bb52017-06-30 19:14:49 +053099static constexpr auto initiateErase = 0xAA;
100static constexpr auto getEraseStatus = 0x00;
101static constexpr auto eraseComplete = 0x01;
102
103/** @struct ClearSELRequest
104 *
105 * IPMI payload for Clear SEL command request.
106 */
107struct ClearSELRequest
108{
Patrick Venture0b02be92018-08-31 11:55:55 -0700109 uint16_t reservationID; //!< Reservation ID.
110 uint8_t charC; //!< Char 'C'(0x43h).
111 uint8_t charL; //!< Char 'L'(0x4Ch).
112 uint8_t charR; //!< Char 'R'(0x52h).
113 uint8_t eraseOperation; //!< Erase operation.
Tom Joseph2f05bb52017-06-30 19:14:49 +0530114} __attribute__((packed));
115
Tom Joseph6edc8a02017-06-30 18:52:56 +0530116/** @brief Convert logging entry to SEL
117 *
118 * @param[in] objPath - DBUS object path of the logging entry.
119 *
120 * @return On success return the response of Get SEL entry command.
121 */
122GetSELEntryResponse convertLogEntrytoSEL(const std::string& objPath);
123
Tom Joseph399fd922017-06-30 18:40:30 +0530124/** @brief Get the timestamp of the log entry
125 *
126 * @param[in] objPath - DBUS object path of the logging entry.
127 *
128 * @return On success return the timestamp of the log entry as number of
129 * seconds from epoch.
130 */
131std::chrono::seconds getEntryTimeStamp(const std::string& objPath);
Tom Joseph6edc8a02017-06-30 18:52:56 +0530132
Tom Joseph232f5292017-07-07 20:14:02 +0530133/** @brief Read the logging entry object paths
134 *
135 * This API would read the logging dbus logging entry object paths and sorting
136 * the filename in the numeric order. The paths is cleared before populating
137 * the object paths.
138 *
139 * @param[in,out] paths - sorted list of logging entry object paths.
140 *
141 * @note This function is invoked when the Get SEL Info command or the Delete
142 * SEL entry command is invoked. The Get SEL Entry command is preceded
143 * typically by Get SEL Info command, so readLoggingObjectPaths is not
144 * invoked before each Get SEL entry command.
145 */
146void readLoggingObjectPaths(ObjectPaths& paths);
147
Tom Joseph6b7a1432017-05-19 10:43:36 +0530148namespace internal
149{
150
151/** @brief Convert logging entry to SEL event record
152 *
153 * @param[in] objPath - DBUS object path of the logging entry.
154 * @param[in] iter - Iterator to the sensor data corresponding to the logging
155 * entry
156 *
157 * @return On success return the SEL event record, throw an exception in case
158 * of failure.
159 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700160GetSELEntryResponse
161 prepareSELEntry(const std::string& objPath,
162 ipmi::sensor::InvObjectIDMap::const_iterator iter);
Tom Joseph6b7a1432017-05-19 10:43:36 +0530163
Patrick Venture0b02be92018-08-31 11:55:55 -0700164} // namespace internal
Tom Joseph6b7a1432017-05-19 10:43:36 +0530165
166} // namespace sel
167
168} // namespace ipmi