1 #pragma once 2 3 #include "types.hpp" 4 5 #include <chrono> 6 #include <cstdint> 7 #include <sdbusplus/server.hpp> 8 9 namespace ipmi 10 { 11 12 namespace sel 13 { 14 15 static constexpr auto mapperBusName = "xyz.openbmc_project.ObjectMapper"; 16 static constexpr auto mapperObjPath = "/xyz/openbmc_project/object_mapper"; 17 static constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper"; 18 19 static constexpr auto logBasePath = "/xyz/openbmc_project/logging/entry"; 20 static constexpr auto logEntryIntf = "xyz.openbmc_project.Logging.Entry"; 21 static constexpr auto logDeleteIntf = "xyz.openbmc_project.Object.Delete"; 22 23 static constexpr auto propIntf = "org.freedesktop.DBus.Properties"; 24 25 using ObjectPaths = std::vector<std::string>; 26 using PropertyName = std::string; 27 using Resolved = bool; 28 using Id = uint32_t; 29 using Timestamp = uint64_t; 30 using Message = std::string; 31 using AdditionalData = std::vector<std::string>; 32 using PropertyType = sdbusplus::message::variant<Resolved, Id, Timestamp, 33 Message, AdditionalData>; 34 35 static constexpr auto selVersion = 0x51; 36 static constexpr auto invalidTimeStamp = 0xFFFFFFFF; 37 static constexpr auto operationSupport = 0x0A; 38 39 /** @struct GetSELInfoResponse 40 * 41 * IPMI payload for Get SEL Info command response. 42 */ 43 struct GetSELInfoResponse 44 { 45 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. 51 } __attribute__((packed)); 52 53 static constexpr auto firstEntry = 0x0000; 54 static constexpr auto lastEntry = 0xFFFF; 55 static constexpr auto entireRecord = 0xFF; 56 static constexpr auto selRecordSize = 16; 57 58 /** @struct GetSELEntryRequest 59 * 60 * IPMI payload for Get SEL Entry command request. 61 */ 62 struct GetSELEntryRequest 63 { 64 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. 68 } __attribute__((packed)); 69 70 /** @struct GetSELEntryResponse 71 * 72 * IPMI payload for Get SEL Entry command response. 73 */ 74 struct GetSELEntryResponse 75 { 76 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. 88 } __attribute__((packed)); 89 90 /** @struct DeleteSELEntryRequest 91 * 92 * IPMI payload for Delete SEL Entry command request. 93 */ 94 struct DeleteSELEntryRequest 95 { 96 uint16_t reservationID; //!< Reservation ID. 97 uint16_t selRecordID; //!< SEL Record ID. 98 } __attribute__((packed)); 99 100 static constexpr auto initiateErase = 0xAA; 101 static constexpr auto getEraseStatus = 0x00; 102 static constexpr auto eraseComplete = 0x01; 103 104 /** @struct ClearSELRequest 105 * 106 * IPMI payload for Clear SEL command request. 107 */ 108 struct ClearSELRequest 109 { 110 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. 115 } __attribute__((packed)); 116 117 /** @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 */ 123 GetSELEntryResponse convertLogEntrytoSEL(const std::string& objPath); 124 125 /** @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 */ 132 std::chrono::seconds getEntryTimeStamp(const std::string& objPath); 133 134 /** @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 */ 147 void readLoggingObjectPaths(ObjectPaths& paths); 148 149 namespace 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 */ 161 GetSELEntryResponse 162 prepareSELEntry(const std::string& objPath, 163 ipmi::sensor::InvObjectIDMap::const_iterator iter); 164 165 } // namespace internal 166 167 } // namespace sel 168 169 } // namespace ipmi 170