blob: 4e2855a5c85511127200da91dcf7f45c94f78523 [file] [log] [blame]
Tom Joseph6b7a1432017-05-19 10:43:36 +05301#pragma once
2
Patrick Venture0b02be92018-08-31 11:55:55 -07003#include "types.hpp"
4
Yong Li021f2d12018-09-26 16:09:22 +08005#include <chrono>
Tom Joseph6b7a1432017-05-19 10:43:36 +05306#include <cstdint>
7#include <sdbusplus/server.hpp>
Tom Joseph6b7a1432017-05-19 10:43:36 +05308
9namespace ipmi
10{
11
12namespace sel
13{
14
15static constexpr auto mapperBusName = "xyz.openbmc_project.ObjectMapper";
16static constexpr auto mapperObjPath = "/xyz/openbmc_project/object_mapper";
17static constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper";
18
19static constexpr auto logBasePath = "/xyz/openbmc_project/logging/entry";
20static constexpr auto logEntryIntf = "xyz.openbmc_project.Logging.Entry";
21static constexpr auto logDeleteIntf = "xyz.openbmc_project.Object.Delete";
22
23static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
24
Tom Joseph232f5292017-07-07 20:14:02 +053025using ObjectPaths = std::vector<std::string>;
Tom Joseph306878b2017-07-10 19:30:54 +053026using PropertyName = std::string;
27using Resolved = bool;
28using Id = uint32_t;
29using Timestamp = uint64_t;
30using Message = std::string;
31using AdditionalData = std::vector<std::string>;
32using PropertyType = sdbusplus::message::variant<Resolved, Id, Timestamp,
Patrick Venture0b02be92018-08-31 11:55:55 -070033 Message, AdditionalData>;
Tom Joseph6b7a1432017-05-19 10:43:36 +053034
Tom Joseph6f7deaa2017-06-30 19:03:54 +053035static constexpr auto selVersion = 0x51;
36static constexpr auto invalidTimeStamp = 0xFFFFFFFF;
37static constexpr auto operationSupport = 0x0A;
38
39/** @struct GetSELInfoResponse
40 *
41 * IPMI payload for Get SEL Info command response.
42 */
43struct GetSELInfoResponse
44{
Patrick Venture0b02be92018-08-31 11:55:55 -070045 uint8_t selVersion; //!< SEL revision.
46 uint16_t entries; //!< Number of log entries in SEL.
47 uint16_t freeSpace; //!< Free Space in bytes.
48 uint32_t addTimeStamp; //!< Most recent addition timestamp.
49 uint32_t eraseTimeStamp; //!< Most recent erase timestamp.
50 uint8_t operationSupport; //!< Operation support.
Tom Joseph6f7deaa2017-06-30 19:03:54 +053051} __attribute__((packed));
52
Tom Josepha4953392017-06-30 19:09:47 +053053static constexpr auto firstEntry = 0x0000;
54static constexpr auto lastEntry = 0xFFFF;
55static constexpr auto entireRecord = 0xFF;
56static constexpr auto selRecordSize = 16;
57
58/** @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
Tom Joseph6b7a1432017-05-19 10:43:36 +053070/** @struct GetSELEntryResponse
71 *
72 * IPMI payload for Get SEL Entry command response.
73 */
74struct GetSELEntryResponse
75{
Patrick Venture0b02be92018-08-31 11:55:55 -070076 uint16_t nextRecordID; //!< Next RecordID.
77 uint16_t recordID; //!< Record ID.
78 uint8_t recordType; //!< Record Type.
79 uint32_t timeStamp; //!< Timestamp.
80 uint16_t generatorID; //!< Generator ID.
81 uint8_t eventMsgRevision; //!< Event Message Revision.
82 uint8_t sensorType; //!< Sensor Type.
83 uint8_t sensorNum; //!< Sensor Number.
84 uint8_t eventType; //!< Event Dir | Event Type.
85 uint8_t eventData1; //!< Event Data 1.
86 uint8_t eventData2; //!< Event Data 2.
87 uint8_t eventData3; //!< Event Data 3.
Tom Joseph6b7a1432017-05-19 10:43:36 +053088} __attribute__((packed));
89
Tom Joseph8f4a2aa2017-06-30 19:12:49 +053090/** @struct DeleteSELEntryRequest
91 *
92 * IPMI payload for Delete SEL Entry command request.
93 */
94struct DeleteSELEntryRequest
95{
Patrick Venture0b02be92018-08-31 11:55:55 -070096 uint16_t reservationID; //!< Reservation ID.
97 uint16_t selRecordID; //!< SEL Record ID.
Tom Joseph8f4a2aa2017-06-30 19:12:49 +053098} __attribute__((packed));
99
Tom Joseph2f05bb52017-06-30 19:14:49 +0530100static constexpr auto initiateErase = 0xAA;
101static constexpr auto getEraseStatus = 0x00;
102static constexpr auto eraseComplete = 0x01;
103
104/** @struct ClearSELRequest
105 *
106 * IPMI payload for Clear SEL command request.
107 */
108struct ClearSELRequest
109{
Patrick Venture0b02be92018-08-31 11:55:55 -0700110 uint16_t reservationID; //!< Reservation ID.
111 uint8_t charC; //!< Char 'C'(0x43h).
112 uint8_t charL; //!< Char 'L'(0x4Ch).
113 uint8_t charR; //!< Char 'R'(0x52h).
114 uint8_t eraseOperation; //!< Erase operation.
Tom Joseph2f05bb52017-06-30 19:14:49 +0530115} __attribute__((packed));
116
Tom Joseph6edc8a02017-06-30 18:52:56 +0530117/** @brief Convert logging entry to SEL
118 *
119 * @param[in] objPath - DBUS object path of the logging entry.
120 *
121 * @return On success return the response of Get SEL entry command.
122 */
123GetSELEntryResponse convertLogEntrytoSEL(const std::string& objPath);
124
Tom Joseph399fd922017-06-30 18:40:30 +0530125/** @brief Get the timestamp of the log entry
126 *
127 * @param[in] objPath - DBUS object path of the logging entry.
128 *
129 * @return On success return the timestamp of the log entry as number of
130 * seconds from epoch.
131 */
132std::chrono::seconds getEntryTimeStamp(const std::string& objPath);
Tom Joseph6edc8a02017-06-30 18:52:56 +0530133
Tom Joseph232f5292017-07-07 20:14:02 +0530134/** @brief Read the logging entry object paths
135 *
136 * This API would read the logging dbus logging entry object paths and sorting
137 * the filename in the numeric order. The paths is cleared before populating
138 * the object paths.
139 *
140 * @param[in,out] paths - sorted list of logging entry object paths.
141 *
142 * @note This function is invoked when the Get SEL Info command or the Delete
143 * SEL entry command is invoked. The Get SEL Entry command is preceded
144 * typically by Get SEL Info command, so readLoggingObjectPaths is not
145 * invoked before each Get SEL entry command.
146 */
147void readLoggingObjectPaths(ObjectPaths& paths);
148
Tom Joseph6b7a1432017-05-19 10:43:36 +0530149namespace internal
150{
151
152/** @brief Convert logging entry to SEL event record
153 *
154 * @param[in] objPath - DBUS object path of the logging entry.
155 * @param[in] iter - Iterator to the sensor data corresponding to the logging
156 * entry
157 *
158 * @return On success return the SEL event record, throw an exception in case
159 * of failure.
160 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700161GetSELEntryResponse
162 prepareSELEntry(const std::string& objPath,
163 ipmi::sensor::InvObjectIDMap::const_iterator iter);
Tom Joseph6b7a1432017-05-19 10:43:36 +0530164
Patrick Venture0b02be92018-08-31 11:55:55 -0700165} // namespace internal
Tom Joseph6b7a1432017-05-19 10:43:36 +0530166
167} // namespace sel
168
169} // namespace ipmi