1 #pragma once 2 3 #include <ipmid/types.hpp> 4 #include <sdbusplus/server.hpp> 5 6 #include <chrono> 7 #include <cstdint> 8 #include <iomanip> 9 #include <iostream> 10 #include <sstream> 11 12 namespace ipmi 13 { 14 15 namespace sel 16 { 17 18 static constexpr auto mapperBusName = "xyz.openbmc_project.ObjectMapper"; 19 static constexpr auto mapperObjPath = "/xyz/openbmc_project/object_mapper"; 20 static constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper"; 21 22 static constexpr auto logWatchPath = "/xyz/openbmc_project/logging"; 23 static constexpr auto logBasePath = "/xyz/openbmc_project/logging/entry"; 24 static constexpr auto logEntryIntf = "xyz.openbmc_project.Logging.Entry"; 25 static constexpr auto logDeleteIntf = "xyz.openbmc_project.Object.Delete"; 26 27 static constexpr auto logObj = "/xyz/openbmc_project/logging"; 28 static constexpr auto logIntf = "xyz.openbmc_project.Collection.DeleteAll"; 29 static constexpr auto logDeleteAllMethod = "DeleteAll"; 30 31 static constexpr auto propIntf = "org.freedesktop.DBus.Properties"; 32 33 using ObjectPaths = std::vector<std::string>; 34 using PropertyName = std::string; 35 using Resolved = bool; 36 using Id = uint32_t; 37 using Timestamp = uint64_t; 38 using Message = std::string; 39 using AdditionalData = std::map<std::string, std::string>; 40 using PropertyType = 41 std::variant<Resolved, Id, Timestamp, Message, AdditionalData>; 42 43 static constexpr auto selVersion = 0x51; 44 static constexpr auto invalidTimeStamp = 0xFFFFFFFF; 45 46 static constexpr auto firstEntry = 0x0000; 47 static constexpr auto lastEntry = 0xFFFF; 48 static constexpr auto entireRecord = 0xFF; 49 static constexpr auto selRecordSize = 16; 50 51 namespace operationSupport 52 { 53 static constexpr bool overflow = false; 54 static constexpr bool deleteSel = true; 55 static constexpr bool partialAddSelEntry = false; 56 static constexpr bool reserveSel = true; 57 static constexpr bool getSelAllocationInfo = false; 58 } // namespace operationSupport 59 60 constexpr size_t SELRecordLength = 16; 61 62 /** @struct SELEventRecord 63 * 64 * IPMI SEL Event Record 65 */ 66 struct SELEventRecord 67 { 68 uint16_t recordID; //!< Record ID. 69 uint8_t recordType; //!< Record Type. 70 uint32_t timeStamp; //!< Timestamp. 71 uint16_t generatorID; //!< Generator ID. 72 uint8_t eventMsgRevision; //!< Event Message Revision. 73 uint8_t sensorType; //!< Sensor Type. 74 uint8_t sensorNum; //!< Sensor Number. 75 uint8_t eventType; //!< Event Dir | Event Type. 76 uint8_t eventData1; //!< Event Data 1. 77 uint8_t eventData2; //!< Event Data 2. 78 uint8_t eventData3; //!< Event Data 3. 79 } __attribute__((packed)); 80 81 static_assert(sizeof(SELEventRecord) == SELRecordLength); 82 83 /** @struct SELOEMRecordTypeCD 84 * 85 * IPMI SEL OEM Record - Type C0h-DFh 86 */ 87 struct SELOEMRecordTypeCD 88 { 89 uint16_t recordID; //!< Record ID. 90 uint8_t recordType; //!< Record Type. 91 uint32_t timeStamp; //!< Timestamp. 92 uint8_t manufacturerID[3]; //!< Manufacturer ID. 93 uint8_t oemDefined[6]; //!< OEM Defined data. 94 } __attribute__((packed)); 95 96 static_assert(sizeof(SELOEMRecordTypeCD) == SELRecordLength); 97 98 /** @struct SELOEMRecordTypeEF 99 * 100 * IPMI SEL OEM Record - Type E0h-FFh 101 */ 102 struct SELOEMRecordTypeEF 103 { 104 uint16_t recordID; //!< Record ID. 105 uint8_t recordType; //!< Record Type. 106 uint8_t oemDefined[13]; //!< OEM Defined data. 107 } __attribute__((packed)); 108 109 static_assert(sizeof(SELOEMRecordTypeEF) == SELRecordLength); 110 111 union SELEventRecordFormat 112 { 113 SELEventRecord eventRecord; 114 SELOEMRecordTypeCD oemCD; 115 SELOEMRecordTypeEF oemEF; 116 }; 117 118 /** @struct GetSELEntryResponse 119 * 120 * IPMI payload for Get SEL Entry command response. 121 */ 122 struct GetSELEntryResponse 123 { 124 uint16_t nextRecordID; //!< Next RecordID. 125 SELEventRecordFormat event; // !< The Event Record. 126 } __attribute__((packed)); 127 128 static_assert(sizeof(GetSELEntryResponse) == 129 SELRecordLength + sizeof(uint16_t)); 130 131 static constexpr auto initiateErase = 0xAA; 132 static constexpr auto getEraseStatus = 0x00; 133 static constexpr auto eraseComplete = 0x01; 134 135 /** @brief Convert logging entry to SEL 136 * 137 * @param[in] objPath - DBUS object path of the logging entry. 138 * 139 * @return On success return the response of Get SEL entry command. 140 */ 141 GetSELEntryResponse convertLogEntrytoSEL(const std::string& objPath); 142 143 /** @brief Get the timestamp of the log entry 144 * 145 * @param[in] objPath - DBUS object path of the logging entry. 146 * 147 * @return On success return the timestamp of the log entry as number of 148 * seconds from epoch. 149 */ 150 std::chrono::seconds getEntryTimeStamp(const std::string& objPath); 151 152 /** @brief Read the logging entry object paths 153 * 154 * This API would read the logging dbus logging entry object paths and sorting 155 * the filename in the numeric order. The paths is cleared before populating 156 * the object paths. 157 * 158 * @param[in,out] paths - sorted list of logging entry object paths. 159 * 160 * @note This function is invoked when the Get SEL Info command or the Delete 161 * SEL entry command is invoked. The Get SEL Entry command is preceded 162 * typically by Get SEL Info command, so readLoggingObjectPaths is not 163 * invoked before each Get SEL entry command. 164 */ 165 void readLoggingObjectPaths(ObjectPaths& paths); 166 167 template <typename T> toHexStr(const T & data)168std::string toHexStr(const T& data) 169 { 170 std::stringstream stream; 171 stream << std::hex << std::uppercase << std::setfill('0'); 172 for (const auto& v : data) 173 { 174 stream << std::setw(2) << static_cast<int>(v); 175 } 176 return stream.str(); 177 } 178 namespace internal 179 { 180 181 /** @brief Convert logging entry to SEL event record 182 * 183 * @param[in] objPath - DBUS object path of the logging entry. 184 * @param[in] iter - Iterator to the sensor data corresponding to the logging 185 * entry 186 * 187 * @return On success return the SEL event record, throw an exception in case 188 * of failure. 189 */ 190 GetSELEntryResponse prepareSELEntry( 191 const std::string& objPath, 192 ipmi::sensor::InvObjectIDMap::const_iterator iter); 193 194 } // namespace internal 195 196 } // namespace sel 197 198 } // namespace ipmi 199