1 #pragma once 2 3 #include <cstdint> 4 #include <sdbusplus/server.hpp> 5 #include "types.hpp" 6 7 namespace ipmi 8 { 9 10 namespace sel 11 { 12 13 static constexpr auto mapperBusName = "xyz.openbmc_project.ObjectMapper"; 14 static constexpr auto mapperObjPath = "/xyz/openbmc_project/object_mapper"; 15 static constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper"; 16 17 static constexpr auto logBasePath = "/xyz/openbmc_project/logging/entry"; 18 static constexpr auto logEntryIntf = "xyz.openbmc_project.Logging.Entry"; 19 static constexpr auto logDeleteIntf = "xyz.openbmc_project.Object.Delete"; 20 21 static constexpr auto propIntf = "org.freedesktop.DBus.Properties"; 22 23 using ObjectPaths = std::vector<std::string>; 24 using PropertyName = std::string; 25 using Resolved = bool; 26 using Id = uint32_t; 27 using Timestamp = uint64_t; 28 using Message = std::string; 29 using AdditionalData = std::vector<std::string>; 30 using PropertyType = sdbusplus::message::variant<Resolved, Id, Timestamp, 31 Message, AdditionalData>; 32 33 static constexpr auto selVersion = 0x51; 34 static constexpr auto invalidTimeStamp = 0xFFFFFFFF; 35 static constexpr auto operationSupport = 0x0A; 36 37 /** @struct GetSELInfoResponse 38 * 39 * IPMI payload for Get SEL Info command response. 40 */ 41 struct GetSELInfoResponse 42 { 43 uint8_t selVersion; //!< SEL revision. 44 uint16_t entries; //!< Number of log entries in SEL. 45 uint16_t freeSpace; //!< Free Space in bytes. 46 uint32_t addTimeStamp; //!< Most recent addition timestamp. 47 uint32_t eraseTimeStamp; //!< Most recent erase timestamp. 48 uint8_t operationSupport; //!< Operation support. 49 } __attribute__((packed)); 50 51 static constexpr auto firstEntry = 0x0000; 52 static constexpr auto lastEntry = 0xFFFF; 53 static constexpr auto entireRecord = 0xFF; 54 static constexpr auto selRecordSize = 16; 55 56 /** @struct GetSELEntryRequest 57 * 58 * IPMI payload for Get SEL Entry command request. 59 */ 60 struct GetSELEntryRequest 61 { 62 uint16_t reservationID; //!< Reservation ID. 63 uint16_t selRecordID; //!< SEL Record ID. 64 uint8_t offset; //!< Offset into record. 65 uint8_t readLength; //!< Bytes to read. 66 } __attribute__((packed)); 67 68 /** @struct GetSELEntryResponse 69 * 70 * IPMI payload for Get SEL Entry command response. 71 */ 72 struct GetSELEntryResponse 73 { 74 uint16_t nextRecordID; //!< Next RecordID. 75 uint16_t recordID; //!< Record ID. 76 uint8_t recordType; //!< Record Type. 77 uint32_t timeStamp; //!< Timestamp. 78 uint16_t generatorID; //!< Generator ID. 79 uint8_t eventMsgRevision; //!< Event Message Revision. 80 uint8_t sensorType; //!< Sensor Type. 81 uint8_t sensorNum; //!< Sensor Number. 82 uint8_t eventType; //!< Event Dir | Event Type. 83 uint8_t eventData1; //!< Event Data 1. 84 uint8_t eventData2; //!< Event Data 2. 85 uint8_t eventData3; //!< Event Data 3. 86 } __attribute__((packed)); 87 88 /** @struct DeleteSELEntryRequest 89 * 90 * IPMI payload for Delete SEL Entry command request. 91 */ 92 struct DeleteSELEntryRequest 93 { 94 uint16_t reservationID; //!< Reservation ID. 95 uint16_t selRecordID; //!< SEL Record ID. 96 } __attribute__((packed)); 97 98 static constexpr auto initiateErase = 0xAA; 99 static constexpr auto getEraseStatus = 0x00; 100 static constexpr auto eraseComplete = 0x01; 101 102 /** @struct ClearSELRequest 103 * 104 * IPMI payload for Clear SEL command request. 105 */ 106 struct ClearSELRequest 107 { 108 uint16_t reservationID; //!< Reservation ID. 109 uint8_t charC; //!< Char 'C'(0x43h). 110 uint8_t charL; //!< Char 'L'(0x4Ch). 111 uint8_t charR; //!< Char 'R'(0x52h). 112 uint8_t eraseOperation; //!< Erase operation. 113 } __attribute__((packed)); 114 115 /** @brief Convert logging entry to SEL 116 * 117 * @param[in] objPath - DBUS object path of the logging entry. 118 * 119 * @return On success return the response of Get SEL entry command. 120 */ 121 GetSELEntryResponse convertLogEntrytoSEL(const std::string& objPath); 122 123 /** @brief Get the timestamp of the log entry 124 * 125 * @param[in] objPath - DBUS object path of the logging entry. 126 * 127 * @return On success return the timestamp of the log entry as number of 128 * seconds from epoch. 129 */ 130 std::chrono::seconds getEntryTimeStamp(const std::string& objPath); 131 132 /** @brief Read the logging entry object paths 133 * 134 * This API would read the logging dbus logging entry object paths and sorting 135 * the filename in the numeric order. The paths is cleared before populating 136 * the object paths. 137 * 138 * @param[in,out] paths - sorted list of logging entry object paths. 139 * 140 * @note This function is invoked when the Get SEL Info command or the Delete 141 * SEL entry command is invoked. The Get SEL Entry command is preceded 142 * typically by Get SEL Info command, so readLoggingObjectPaths is not 143 * invoked before each Get SEL entry command. 144 */ 145 void readLoggingObjectPaths(ObjectPaths& paths); 146 147 namespace internal 148 { 149 150 /** @brief Convert logging entry to SEL event record 151 * 152 * @param[in] objPath - DBUS object path of the logging entry. 153 * @param[in] iter - Iterator to the sensor data corresponding to the logging 154 * entry 155 * 156 * @return On success return the SEL event record, throw an exception in case 157 * of failure. 158 */ 159 GetSELEntryResponse prepareSELEntry( 160 const std::string& objPath, 161 ipmi::sensor::InvObjectIDMap::const_iterator iter); 162 163 } 164 165 } // namespace sel 166 167 } // namespace ipmi 168