1 #pragma once 2 3 #include <chrono> 4 #include <cstdint> 5 #include <ipmid/types.hpp> 6 #include <sdbusplus/server.hpp> 7 8 namespace ipmi 9 { 10 11 namespace sel 12 { 13 14 static constexpr auto mapperBusName = "xyz.openbmc_project.ObjectMapper"; 15 static constexpr auto mapperObjPath = "/xyz/openbmc_project/object_mapper"; 16 static constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper"; 17 18 static constexpr auto logBasePath = "/xyz/openbmc_project/logging/entry"; 19 static constexpr auto logEntryIntf = "xyz.openbmc_project.Logging.Entry"; 20 static constexpr auto logDeleteIntf = "xyz.openbmc_project.Object.Delete"; 21 22 static constexpr auto propIntf = "org.freedesktop.DBus.Properties"; 23 24 using ObjectPaths = std::vector<std::string>; 25 using PropertyName = std::string; 26 using Resolved = bool; 27 using Id = uint32_t; 28 using Timestamp = uint64_t; 29 using Message = std::string; 30 using AdditionalData = std::vector<std::string>; 31 using PropertyType = 32 std::variant<Resolved, Id, Timestamp, Message, AdditionalData>; 33 34 static constexpr auto selVersion = 0x51; 35 static constexpr auto invalidTimeStamp = 0xFFFFFFFF; 36 static constexpr auto operationSupport = 0x0A; 37 38 /** @struct GetSELInfoResponse 39 * 40 * IPMI payload for Get SEL Info command response. 41 */ 42 struct GetSELInfoResponse 43 { 44 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. 50 } __attribute__((packed)); 51 52 static constexpr auto firstEntry = 0x0000; 53 static constexpr auto lastEntry = 0xFFFF; 54 static constexpr auto entireRecord = 0xFF; 55 static constexpr auto selRecordSize = 16; 56 57 /** @struct GetSELEntryRequest 58 * 59 * IPMI payload for Get SEL Entry command request. 60 */ 61 struct GetSELEntryRequest 62 { 63 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. 67 } __attribute__((packed)); 68 69 /** @struct GetSELEntryResponse 70 * 71 * IPMI payload for Get SEL Entry command response. 72 */ 73 struct GetSELEntryResponse 74 { 75 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. 87 } __attribute__((packed)); 88 89 static constexpr auto initiateErase = 0xAA; 90 static constexpr auto getEraseStatus = 0x00; 91 static constexpr auto eraseComplete = 0x01; 92 93 /** @brief Convert logging entry to SEL 94 * 95 * @param[in] objPath - DBUS object path of the logging entry. 96 * 97 * @return On success return the response of Get SEL entry command. 98 */ 99 GetSELEntryResponse convertLogEntrytoSEL(const std::string& objPath); 100 101 /** @brief Get the timestamp of the log entry 102 * 103 * @param[in] objPath - DBUS object path of the logging entry. 104 * 105 * @return On success return the timestamp of the log entry as number of 106 * seconds from epoch. 107 */ 108 std::chrono::seconds getEntryTimeStamp(const std::string& objPath); 109 110 /** @brief Read the logging entry object paths 111 * 112 * This API would read the logging dbus logging entry object paths and sorting 113 * the filename in the numeric order. The paths is cleared before populating 114 * the object paths. 115 * 116 * @param[in,out] paths - sorted list of logging entry object paths. 117 * 118 * @note This function is invoked when the Get SEL Info command or the Delete 119 * SEL entry command is invoked. The Get SEL Entry command is preceded 120 * typically by Get SEL Info command, so readLoggingObjectPaths is not 121 * invoked before each Get SEL entry command. 122 */ 123 void readLoggingObjectPaths(ObjectPaths& paths); 124 125 namespace internal 126 { 127 128 /** @brief Convert logging entry to SEL event record 129 * 130 * @param[in] objPath - DBUS object path of the logging entry. 131 * @param[in] iter - Iterator to the sensor data corresponding to the logging 132 * entry 133 * 134 * @return On success return the SEL event record, throw an exception in case 135 * of failure. 136 */ 137 GetSELEntryResponse 138 prepareSELEntry(const std::string& objPath, 139 ipmi::sensor::InvObjectIDMap::const_iterator iter); 140 141 } // namespace internal 142 143 } // namespace sel 144 145 } // namespace ipmi 146