Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 3 | #include "types.hpp" |
| 4 | |
Yong Li | 021f2d1 | 2018-09-26 16:09:22 +0800 | [diff] [blame] | 5 | #include <chrono> |
Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 6 | #include <cstdint> |
| 7 | #include <sdbusplus/server.hpp> |
Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 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 | |
Tom Joseph | 232f529 | 2017-07-07 20:14:02 +0530 | [diff] [blame] | 25 | using ObjectPaths = std::vector<std::string>; |
Tom Joseph | 306878b | 2017-07-10 19:30:54 +0530 | [diff] [blame] | 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, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 33 | Message, AdditionalData>; |
Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 34 | |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 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 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 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. |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 51 | } __attribute__((packed)); |
| 52 | |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 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 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 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. |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 68 | } __attribute__((packed)); |
| 69 | |
Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 70 | /** @struct GetSELEntryResponse |
| 71 | * |
| 72 | * IPMI payload for Get SEL Entry command response. |
| 73 | */ |
| 74 | struct GetSELEntryResponse |
| 75 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 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. |
Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 88 | } __attribute__((packed)); |
| 89 | |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 90 | /** @struct DeleteSELEntryRequest |
| 91 | * |
| 92 | * IPMI payload for Delete SEL Entry command request. |
| 93 | */ |
| 94 | struct DeleteSELEntryRequest |
| 95 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 96 | uint16_t reservationID; //!< Reservation ID. |
| 97 | uint16_t selRecordID; //!< SEL Record ID. |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 98 | } __attribute__((packed)); |
| 99 | |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 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 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 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. |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 115 | } __attribute__((packed)); |
| 116 | |
Tom Joseph | 6edc8a0 | 2017-06-30 18:52:56 +0530 | [diff] [blame] | 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 | |
Tom Joseph | 399fd92 | 2017-06-30 18:40:30 +0530 | [diff] [blame] | 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); |
Tom Joseph | 6edc8a0 | 2017-06-30 18:52:56 +0530 | [diff] [blame] | 133 | |
Tom Joseph | 232f529 | 2017-07-07 20:14:02 +0530 | [diff] [blame] | 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 | |
Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 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 | */ |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 161 | GetSELEntryResponse |
| 162 | prepareSELEntry(const std::string& objPath, |
| 163 | ipmi::sensor::InvObjectIDMap::const_iterator iter); |
Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 164 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 165 | } // namespace internal |
Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 166 | |
| 167 | } // namespace sel |
| 168 | |
| 169 | } // namespace ipmi |