Patrick Williams | 768730d | 2023-09-06 16:27:20 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 3 | #include "fruread.hpp" |
| 4 | #include "read_fru_data.hpp" |
| 5 | #include "selutility.hpp" |
| 6 | #include "sensorhandler.hpp" |
| 7 | #include "storageaddsel.hpp" |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 8 | |
Lei YU | 52d9124 | 2017-10-17 22:52:28 +0800 | [diff] [blame] | 9 | #include <arpa/inet.h> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 10 | #include <systemd/sd-bus.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 11 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 12 | #include <ipmid/api.hpp> |
Vernon Mauery | 9cf0838 | 2023-04-28 14:00:11 -0700 | [diff] [blame] | 13 | #include <ipmid/entity_map_json.hpp> |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 14 | #include <ipmid/utils.hpp> |
| 15 | #include <phosphor-logging/elog-errors.hpp> |
| 16 | #include <phosphor-logging/elog.hpp> |
George Liu | 51856e6 | 2024-07-17 19:46:03 +0800 | [diff] [blame] | 17 | #include <phosphor-logging/lg2.hpp> |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 18 | #include <sdbusplus/server.hpp> |
| 19 | #include <xyz/openbmc_project/Common/error.hpp> |
| 20 | #include <xyz/openbmc_project/Logging/SEL/error.hpp> |
| 21 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 22 | #include <algorithm> |
Lei YU | 52d9124 | 2017-10-17 22:52:28 +0800 | [diff] [blame] | 23 | #include <chrono> |
| 24 | #include <cstdio> |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 25 | #include <cstring> |
Vernon Mauery | bdda800 | 2019-02-26 10:18:51 -0800 | [diff] [blame] | 26 | #include <filesystem> |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 27 | #include <optional> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 28 | #include <string> |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 29 | #include <variant> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 30 | |
George Liu | 5087b07 | 2025-03-11 19:28:17 +0800 | [diff] [blame] | 31 | void registerNetFnStorageFunctions() __attribute__((constructor)); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 32 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 33 | unsigned int g_sel_time = 0xFFFFFFFF; |
Patrick Venture | db0cbe6 | 2019-09-09 14:47:22 -0700 | [diff] [blame] | 34 | namespace ipmi |
| 35 | { |
| 36 | namespace sensor |
| 37 | { |
| 38 | extern const IdInfoMap sensors; |
| 39 | } // namespace sensor |
| 40 | } // namespace ipmi |
Lotus Xu | 57d3557 | 2021-01-24 11:13:13 +0800 | [diff] [blame] | 41 | extern const ipmi::sensor::InvObjectIDMap invSensors; |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 42 | extern const FruMap frus; |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 43 | constexpr uint8_t eventDataSize = 3; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 44 | namespace |
| 45 | { |
shamim ali | 071d00c | 2022-03-02 15:42:46 +0530 | [diff] [blame] | 46 | constexpr auto SystemdTimeService = "org.freedesktop.timedate1"; |
| 47 | constexpr auto SystemdTimePath = "/org/freedesktop/timedate1"; |
| 48 | constexpr auto SystemdTimeInterface = "org.freedesktop.timedate1"; |
| 49 | |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 50 | constexpr auto TIME_INTERFACE = "xyz.openbmc_project.Time.EpochTime"; |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 51 | constexpr auto BMC_TIME_PATH = "/xyz/openbmc_project/time/bmc"; |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 52 | constexpr auto DBUS_PROPERTIES = "org.freedesktop.DBus.Properties"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 53 | constexpr auto PROPERTY_ELAPSED = "Elapsed"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 54 | } // namespace |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 55 | |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 56 | using InternalFailure = |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 57 | sdbusplus::error::xyz::openbmc_project::common::InternalFailure; |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 58 | using namespace phosphor::logging; |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 59 | using namespace ipmi::fru; |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 60 | using namespace xyz::openbmc_project::logging::sel; |
Lotus Xu | 57d3557 | 2021-01-24 11:13:13 +0800 | [diff] [blame] | 61 | using SELCreated = |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 62 | sdbusplus::error::xyz::openbmc_project::logging::sel::Created; |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 63 | |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 64 | using SELRecordID = uint16_t; |
| 65 | using SELEntry = ipmi::sel::SELEventRecordFormat; |
| 66 | using SELCacheMap = std::map<SELRecordID, SELEntry>; |
| 67 | |
| 68 | SELCacheMap selCacheMap __attribute__((init_priority(101))); |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 69 | bool selCacheMapInitialized; |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 70 | std::unique_ptr<sdbusplus::bus::match_t> selAddedMatch |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 71 | __attribute__((init_priority(101))); |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 72 | std::unique_ptr<sdbusplus::bus::match_t> selRemovedMatch |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 73 | __attribute__((init_priority(101))); |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 74 | std::unique_ptr<sdbusplus::bus::match_t> selUpdatedMatch |
Lei YU | 4106e42 | 2021-09-15 10:55:51 +0800 | [diff] [blame] | 75 | __attribute__((init_priority(101))); |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 76 | |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 77 | static inline uint16_t getLoggingId(const std::string& p) |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 78 | { |
| 79 | namespace fs = std::filesystem; |
| 80 | fs::path entryPath(p); |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 81 | return std::stoul(entryPath.filename().string()); |
| 82 | } |
| 83 | |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 84 | static inline std::string getLoggingObjPath(uint16_t id) |
| 85 | { |
| 86 | return std::string(ipmi::sel::logBasePath) + "/" + std::to_string(id); |
| 87 | } |
| 88 | |
Patrick Williams | 69b4c28 | 2025-03-03 11:19:13 -0500 | [diff] [blame] | 89 | std::optional<std::pair<uint16_t, SELEntry>> parseLoggingEntry( |
| 90 | const std::string& p) |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 91 | { |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 92 | try |
| 93 | { |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 94 | auto id = getLoggingId(p); |
| 95 | ipmi::sel::GetSELEntryResponse record{}; |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 96 | record = ipmi::sel::convertLogEntrytoSEL(p); |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 97 | return std::pair<uint16_t, SELEntry>({id, std::move(record.event)}); |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 98 | } |
| 99 | catch (const std::exception& e) |
| 100 | { |
| 101 | fprintf(stderr, "Failed to convert %s to SEL: %s\n", p.c_str(), |
| 102 | e.what()); |
| 103 | } |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 104 | return std::nullopt; |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 105 | } |
| 106 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 107 | static void selAddedCallback(sdbusplus::message_t& m) |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 108 | { |
| 109 | sdbusplus::message::object_path objPath; |
| 110 | try |
| 111 | { |
| 112 | m.read(objPath); |
| 113 | } |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 114 | catch (const sdbusplus::exception_t& e) |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 115 | { |
George Liu | 51856e6 | 2024-07-17 19:46:03 +0800 | [diff] [blame] | 116 | lg2::error("Failed to read object path"); |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 117 | return; |
| 118 | } |
| 119 | std::string p = objPath; |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 120 | auto entry = parseLoggingEntry(p); |
| 121 | if (entry) |
| 122 | { |
| 123 | selCacheMap.insert(std::move(*entry)); |
| 124 | } |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 125 | } |
| 126 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 127 | static void selRemovedCallback(sdbusplus::message_t& m) |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 128 | { |
| 129 | sdbusplus::message::object_path objPath; |
| 130 | try |
| 131 | { |
| 132 | m.read(objPath); |
| 133 | } |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 134 | catch (const sdbusplus::exception_t& e) |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 135 | { |
George Liu | 51856e6 | 2024-07-17 19:46:03 +0800 | [diff] [blame] | 136 | lg2::error("Failed to read object path"); |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 137 | } |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 138 | try |
| 139 | { |
| 140 | std::string p = objPath; |
| 141 | selCacheMap.erase(getLoggingId(p)); |
| 142 | } |
| 143 | catch (const std::invalid_argument& e) |
| 144 | { |
George Liu | 51856e6 | 2024-07-17 19:46:03 +0800 | [diff] [blame] | 145 | lg2::error("Invalid logging entry ID"); |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 146 | } |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 147 | } |
| 148 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 149 | static void selUpdatedCallback(sdbusplus::message_t& m) |
Lei YU | 4106e42 | 2021-09-15 10:55:51 +0800 | [diff] [blame] | 150 | { |
| 151 | std::string p = m.get_path(); |
| 152 | auto entry = parseLoggingEntry(p); |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 153 | if (entry) |
| 154 | { |
| 155 | selCacheMap.insert_or_assign(entry->first, std::move(entry->second)); |
| 156 | } |
Lei YU | 4106e42 | 2021-09-15 10:55:51 +0800 | [diff] [blame] | 157 | } |
| 158 | |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 159 | void registerSelCallbackHandler() |
| 160 | { |
| 161 | using namespace sdbusplus::bus::match::rules; |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 162 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 163 | if (!selAddedMatch) |
| 164 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 165 | selAddedMatch = std::make_unique<sdbusplus::bus::match_t>( |
George Liu | 656ae3c | 2024-08-23 16:44:22 +0800 | [diff] [blame] | 166 | bus, interfacesAdded(ipmi::sel::logWatchPath), |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 167 | std::bind(selAddedCallback, std::placeholders::_1)); |
| 168 | } |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 169 | if (!selRemovedMatch) |
| 170 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 171 | selRemovedMatch = std::make_unique<sdbusplus::bus::match_t>( |
George Liu | 656ae3c | 2024-08-23 16:44:22 +0800 | [diff] [blame] | 172 | bus, interfacesRemoved(ipmi::sel::logWatchPath), |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 173 | std::bind(selRemovedCallback, std::placeholders::_1)); |
| 174 | } |
Lei YU | 4106e42 | 2021-09-15 10:55:51 +0800 | [diff] [blame] | 175 | if (!selUpdatedMatch) |
| 176 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 177 | selUpdatedMatch = std::make_unique<sdbusplus::bus::match_t>( |
Lei YU | 4106e42 | 2021-09-15 10:55:51 +0800 | [diff] [blame] | 178 | bus, |
| 179 | type::signal() + member("PropertiesChanged"s) + |
| 180 | interface("org.freedesktop.DBus.Properties"s) + |
George Liu | 656ae3c | 2024-08-23 16:44:22 +0800 | [diff] [blame] | 181 | argN(0, ipmi::sel::logEntryIntf), |
Lei YU | 4106e42 | 2021-09-15 10:55:51 +0800 | [diff] [blame] | 182 | std::bind(selUpdatedCallback, std::placeholders::_1)); |
| 183 | } |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 184 | } |
| 185 | |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 186 | void initSELCache() |
| 187 | { |
Lei YU | c10cda1 | 2022-01-06 16:01:57 +0800 | [diff] [blame] | 188 | registerSelCallbackHandler(); |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 189 | ipmi::sel::ObjectPaths paths; |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 190 | try |
| 191 | { |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 192 | ipmi::sel::readLoggingObjectPaths(paths); |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 193 | } |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 194 | catch (const sdbusplus::exception_t& e) |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 195 | { |
George Liu | 51856e6 | 2024-07-17 19:46:03 +0800 | [diff] [blame] | 196 | lg2::error("Failed to get logging object paths"); |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 197 | return; |
| 198 | } |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 199 | for (const auto& p : paths) |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 200 | { |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 201 | auto entry = parseLoggingEntry(p); |
| 202 | if (entry) |
| 203 | { |
| 204 | selCacheMap.insert(std::move(*entry)); |
| 205 | } |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 206 | } |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 207 | selCacheMapInitialized = true; |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 208 | } |
| 209 | |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 210 | /** |
| 211 | * @enum Device access mode |
| 212 | */ |
| 213 | enum class AccessMode |
| 214 | { |
| 215 | bytes, ///< Device is accessed by bytes |
| 216 | words ///< Device is accessed by words |
| 217 | }; |
| 218 | |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 219 | /** @brief implements the get SEL Info command |
| 220 | * @returns IPMI completion code plus response data |
| 221 | * - selVersion - SEL revision |
| 222 | * - entries - Number of log entries in SEL. |
| 223 | * - freeSpace - Free Space in bytes. |
| 224 | * - addTimeStamp - Most recent addition timestamp |
| 225 | * - eraseTimeStamp - Most recent erase timestamp |
| 226 | * - operationSupport - Reserve & Delete SEL operations supported |
| 227 | */ |
| 228 | |
| 229 | ipmi::RspType<uint8_t, // SEL revision. |
| 230 | uint16_t, // number of log entries in SEL. |
| 231 | uint16_t, // free Space in bytes. |
| 232 | uint32_t, // most recent addition timestamp |
| 233 | uint32_t, // most recent erase timestamp. |
| 234 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 235 | bool, // SEL allocation info supported |
| 236 | bool, // reserve SEL supported |
| 237 | bool, // partial Add SEL Entry supported |
| 238 | bool, // delete SEL supported |
| 239 | uint3_t, // reserved |
| 240 | bool // overflow flag |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 241 | > |
| 242 | ipmiStorageGetSelInfo() |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 243 | { |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 244 | uint16_t entries = 0; |
| 245 | // Most recent addition timestamp. |
| 246 | uint32_t addTimeStamp = ipmi::sel::invalidTimeStamp; |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 247 | |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 248 | if (!selCacheMapInitialized) |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 249 | { |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 250 | // In case the initSELCache() fails, try it again |
| 251 | initSELCache(); |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 252 | } |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 253 | if (!selCacheMap.empty()) |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 254 | { |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 255 | entries = static_cast<uint16_t>(selCacheMap.size()); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 256 | |
| 257 | try |
| 258 | { |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 259 | auto objPath = getLoggingObjPath(selCacheMap.rbegin()->first); |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 260 | addTimeStamp = static_cast<uint32_t>( |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 261 | (ipmi::sel::getEntryTimeStamp(objPath).count())); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 262 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 263 | catch (const InternalFailure& e) |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 264 | {} |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 265 | catch (const std::runtime_error& e) |
| 266 | { |
George Liu | 51856e6 | 2024-07-17 19:46:03 +0800 | [diff] [blame] | 267 | lg2::error("runtime error: {ERROR}", "ERROR", e); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 271 | constexpr uint8_t selVersion = ipmi::sel::selVersion; |
| 272 | constexpr uint16_t freeSpace = 0xFFFF; |
| 273 | constexpr uint32_t eraseTimeStamp = ipmi::sel::invalidTimeStamp; |
| 274 | constexpr uint3_t reserved{0}; |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 275 | |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 276 | return ipmi::responseSuccess( |
| 277 | selVersion, entries, freeSpace, addTimeStamp, eraseTimeStamp, |
| 278 | ipmi::sel::operationSupport::getSelAllocationInfo, |
| 279 | ipmi::sel::operationSupport::reserveSel, |
| 280 | ipmi::sel::operationSupport::partialAddSelEntry, |
| 281 | ipmi::sel::operationSupport::deleteSel, reserved, |
| 282 | ipmi::sel::operationSupport::overflow); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 283 | } |
| 284 | |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 285 | ipmi::RspType<uint16_t, // Next Record ID |
| 286 | std::vector<uint8_t> // SEL data |
| 287 | > |
| 288 | getSELEntry(uint16_t reservationID, uint16_t selRecordID, uint8_t offset, |
| 289 | uint8_t readLength) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 290 | { |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 291 | if (reservationID != 0) |
Jason M. Bills | 851acb1 | 2019-02-04 14:06:57 -0800 | [diff] [blame] | 292 | { |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 293 | if (!checkSELReservation(reservationID)) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 294 | { |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 295 | return ipmi::responseInvalidReservationId(); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 299 | if (!selCacheMapInitialized) |
| 300 | { |
| 301 | // In case the initSELCache() fails, try it again |
| 302 | initSELCache(); |
| 303 | } |
| 304 | |
| 305 | if (selCacheMap.empty()) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 306 | { |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 307 | return ipmi::responseSensorInvalid(); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 308 | } |
| 309 | |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 310 | SELCacheMap::const_iterator iter; |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 311 | |
| 312 | // Check for the requested SEL Entry. |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 313 | if (selRecordID == ipmi::sel::firstEntry) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 314 | { |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 315 | iter = selCacheMap.begin(); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 316 | } |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 317 | else if (selRecordID == ipmi::sel::lastEntry) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 318 | { |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 319 | if (selCacheMap.size() > 1) |
| 320 | { |
| 321 | iter = selCacheMap.end(); |
| 322 | --iter; |
| 323 | } |
| 324 | else |
| 325 | { |
| 326 | // Only one entry exists, return the first |
| 327 | iter = selCacheMap.begin(); |
| 328 | } |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 329 | } |
| 330 | else |
| 331 | { |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 332 | iter = selCacheMap.find(selRecordID); |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 333 | if (iter == selCacheMap.end()) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 334 | { |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 335 | return ipmi::responseSensorInvalid(); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 339 | ipmi::sel::GetSELEntryResponse record{0, iter->second}; |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 340 | // Identify the next SEL record ID |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 341 | ++iter; |
| 342 | if (iter == selCacheMap.end()) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 343 | { |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 344 | record.nextRecordID = ipmi::sel::lastEntry; |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 345 | } |
| 346 | else |
| 347 | { |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 348 | record.nextRecordID = iter->first; |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 349 | } |
| 350 | |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 351 | uint16_t nextRecordID = record.nextRecordID; |
| 352 | std::vector<uint8_t> buffer; |
| 353 | if (readLength == ipmi::sel::entireRecord) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 354 | { |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 355 | buffer.resize(sizeof(record)); |
| 356 | std::memcpy(buffer.data(), &record.event, sizeof(record.event)); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 357 | } |
| 358 | else |
| 359 | { |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 360 | if (offset >= ipmi::sel::selRecordSize || |
| 361 | readLength > ipmi::sel::selRecordSize) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 362 | { |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 363 | return ipmi::responseInvalidFieldRequest(); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 364 | } |
| 365 | |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 366 | auto diff = ipmi::sel::selRecordSize - offset; |
| 367 | auto minReadLength = std::min(diff, static_cast<int>(readLength)); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 368 | |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 369 | buffer.resize(minReadLength); |
Lei YU | 3ad1971 | 2025-01-27 05:23:03 +0000 | [diff] [blame] | 370 | const ipmi::sel::SELEventRecordFormat* evt = &record.event; |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 371 | std::memcpy(buffer.data(), |
| 372 | reinterpret_cast<const uint8_t*>(evt) + offset, |
| 373 | minReadLength); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 374 | } |
| 375 | |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 376 | return ipmi::responseSuccess(nextRecordID, buffer); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 377 | } |
| 378 | |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 379 | /** @brief implements the delete SEL entry command |
| 380 | * @request |
| 381 | * - reservationID; // reservation ID. |
| 382 | * - selRecordID; // SEL record ID. |
| 383 | * |
| 384 | * @returns ipmi completion code plus response data |
| 385 | * - Record ID of the deleted record |
| 386 | */ |
| 387 | ipmi::RspType<uint16_t // deleted record ID |
| 388 | > |
| 389 | deleteSELEntry(uint16_t reservationID, uint16_t selRecordID) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 390 | { |
Brad Bishop | 1a4117b | 2018-11-21 15:48:18 -0500 | [diff] [blame] | 391 | namespace fs = std::filesystem; |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 392 | |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 393 | if (!checkSELReservation(reservationID)) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 394 | { |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 395 | return ipmi::responseInvalidReservationId(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 396 | } |
| 397 | |
Jason M. Bills | 13e67c8 | 2018-09-10 14:12:16 -0700 | [diff] [blame] | 398 | // Per the IPMI spec, need to cancel the reservation when a SEL entry is |
| 399 | // deleted |
| 400 | cancelSELReservation(); |
| 401 | |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 402 | if (!selCacheMapInitialized) |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 403 | { |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 404 | // In case the initSELCache() fails, try it again |
| 405 | initSELCache(); |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 406 | } |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 407 | |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 408 | if (selCacheMap.empty()) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 409 | { |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 410 | return ipmi::responseSensorInvalid(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 411 | } |
| 412 | |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 413 | SELCacheMap::const_iterator iter; |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 414 | uint16_t delRecordID = 0; |
| 415 | |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 416 | if (selRecordID == ipmi::sel::firstEntry) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 417 | { |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 418 | delRecordID = selCacheMap.begin()->first; |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 419 | } |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 420 | else if (selRecordID == ipmi::sel::lastEntry) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 421 | { |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 422 | delRecordID = selCacheMap.rbegin()->first; |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 423 | } |
| 424 | else |
| 425 | { |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 426 | delRecordID = selRecordID; |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 427 | } |
| 428 | |
Jian | 7d5f481 | 2022-02-23 19:30:27 +0800 | [diff] [blame] | 429 | iter = selCacheMap.find(delRecordID); |
| 430 | if (iter == selCacheMap.end()) |
| 431 | { |
| 432 | return ipmi::responseSensorInvalid(); |
| 433 | } |
| 434 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 435 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 436 | std::string service; |
| 437 | |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 438 | auto objPath = getLoggingObjPath(iter->first); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 439 | try |
| 440 | { |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 441 | service = ipmi::getService(bus, ipmi::sel::logDeleteIntf, objPath); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 442 | } |
| 443 | catch (const std::runtime_error& e) |
| 444 | { |
George Liu | 51856e6 | 2024-07-17 19:46:03 +0800 | [diff] [blame] | 445 | lg2::error("runtime error: {ERROR}", "ERROR", e); |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 446 | return ipmi::responseUnspecifiedError(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 447 | } |
| 448 | |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 449 | auto methodCall = bus.new_method_call(service.c_str(), objPath.c_str(), |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 450 | ipmi::sel::logDeleteIntf, "Delete"); |
George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 451 | try |
| 452 | { |
| 453 | auto reply = bus.call(methodCall); |
| 454 | } |
| 455 | catch (const std::exception& e) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 456 | { |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 457 | return ipmi::responseUnspecifiedError(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 458 | } |
| 459 | |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 460 | return ipmi::responseSuccess(delRecordID); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 461 | } |
| 462 | |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 463 | /** @brief implements the Clear SEL command |
| 464 | * @request |
| 465 | * - reservationID // Reservation ID. |
| 466 | * - clr // char array { 'C'(0x43h), 'L'(0x4Ch), 'R'(0x52h) } |
| 467 | * - eraseOperation; // requested operation. |
| 468 | * |
| 469 | * @returns ipmi completion code plus response data |
| 470 | * - erase status |
| 471 | */ |
| 472 | |
| 473 | ipmi::RspType<uint8_t // erase status |
| 474 | > |
| 475 | clearSEL(uint16_t reservationID, const std::array<char, 3>& clr, |
| 476 | uint8_t eraseOperation) |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 477 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 478 | static constexpr std::array<char, 3> clrOk = {'C', 'L', 'R'}; |
| 479 | if (clr != clrOk) |
Jason M. Bills | 851acb1 | 2019-02-04 14:06:57 -0800 | [diff] [blame] | 480 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 481 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 851acb1 | 2019-02-04 14:06:57 -0800 | [diff] [blame] | 482 | } |
| 483 | |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 484 | if (!checkSELReservation(reservationID)) |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 485 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 486 | return ipmi::responseInvalidReservationId(); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 487 | } |
| 488 | |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 489 | /* |
| 490 | * Erasure status cannot be fetched from DBUS, so always return erasure |
| 491 | * status as `erase completed`. |
| 492 | */ |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 493 | if (eraseOperation == ipmi::sel::getEraseStatus) |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 494 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 495 | return ipmi::responseSuccess( |
| 496 | static_cast<uint8_t>(ipmi::sel::eraseComplete)); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 497 | } |
| 498 | |
Xiaoyu Ma | 73d0777 | 2024-02-04 10:31:37 +0800 | [diff] [blame] | 499 | // Check that initiate erase is correct |
| 500 | if (eraseOperation != ipmi::sel::initiateErase) |
| 501 | { |
| 502 | return ipmi::responseInvalidFieldRequest(); |
| 503 | } |
| 504 | |
Jason M. Bills | 13e67c8 | 2018-09-10 14:12:16 -0700 | [diff] [blame] | 505 | // Per the IPMI spec, need to cancel any reservation when the SEL is cleared |
| 506 | cancelSELReservation(); |
| 507 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 508 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
Lotus Xu | 78fe1b1 | 2021-05-23 17:26:56 +0800 | [diff] [blame] | 509 | auto service = ipmi::getService(bus, ipmi::sel::logIntf, ipmi::sel::logObj); |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 510 | auto method = |
| 511 | bus.new_method_call(service.c_str(), ipmi::sel::logObj, |
| 512 | ipmi::sel::logIntf, ipmi::sel::logDeleteAllMethod); |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 513 | try |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 514 | { |
Lotus Xu | 78fe1b1 | 2021-05-23 17:26:56 +0800 | [diff] [blame] | 515 | bus.call_noreply(method); |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 516 | } |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 517 | catch (const sdbusplus::exception_t& e) |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 518 | { |
George Liu | 51856e6 | 2024-07-17 19:46:03 +0800 | [diff] [blame] | 519 | lg2::error("Error eraseAll: {ERROR}", "ERROR", e); |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 520 | return ipmi::responseUnspecifiedError(); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 521 | } |
| 522 | |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 523 | return ipmi::responseSuccess( |
| 524 | static_cast<uint8_t>(ipmi::sel::eraseComplete)); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 525 | } |
| 526 | |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 527 | /** @brief implements the get SEL time command |
| 528 | * @returns IPMI completion code plus response data |
| 529 | * -current time |
| 530 | */ |
| 531 | ipmi::RspType<uint32_t> // current time |
| 532 | ipmiStorageGetSelTime() |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 533 | { |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 534 | using namespace std::chrono; |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 535 | uint64_t bmc_time_usec = 0; |
| 536 | std::stringstream bmcTime; |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 537 | |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 538 | try |
| 539 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 540 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 541 | auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH); |
George Liu | 42f64ef | 2024-02-05 15:03:18 +0800 | [diff] [blame] | 542 | auto propValue = ipmi::getDbusProperty( |
| 543 | bus, service, BMC_TIME_PATH, TIME_INTERFACE, PROPERTY_ELAPSED); |
| 544 | bmc_time_usec = std::get<uint64_t>(propValue); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 545 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 546 | catch (const InternalFailure& e) |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 547 | { |
George Liu | 51856e6 | 2024-07-17 19:46:03 +0800 | [diff] [blame] | 548 | lg2::error("Internal Failure: {ERROR}", "ERROR", e); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 549 | return ipmi::responseUnspecifiedError(); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 550 | } |
Tom Joseph | 30fd0a1 | 2019-09-24 06:53:22 +0530 | [diff] [blame] | 551 | catch (const std::exception& e) |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 552 | { |
George Liu | 51856e6 | 2024-07-17 19:46:03 +0800 | [diff] [blame] | 553 | lg2::error("exception message: {ERROR}", "ERROR", e); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 554 | return ipmi::responseUnspecifiedError(); |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 555 | } |
| 556 | |
George Liu | 51856e6 | 2024-07-17 19:46:03 +0800 | [diff] [blame] | 557 | lg2::debug("BMC time: {BMC_TIME}", "BMC_TIME", |
| 558 | duration_cast<seconds>(microseconds(bmc_time_usec)).count()); |
Nagaraju Goruganti | 8960b7c | 2018-04-29 22:38:40 -0500 | [diff] [blame] | 559 | |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 560 | // Time is really long int but IPMI wants just uint32. This works okay until |
| 561 | // the number of seconds since 1970 overflows uint32 size.. Still a whole |
| 562 | // lot of time here to even think about that. |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 563 | return ipmi::responseSuccess( |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 564 | duration_cast<seconds>(microseconds(bmc_time_usec)).count()); |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 565 | } |
| 566 | |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 567 | /** @brief implements the set SEL time command |
| 568 | * @param selDeviceTime - epoch time |
| 569 | * -local time as the number of seconds from 00:00:00, January 1, 1970 |
| 570 | * @returns IPMI completion code |
| 571 | */ |
| 572 | ipmi::RspType<> ipmiStorageSetSelTime(uint32_t selDeviceTime) |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 573 | { |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 574 | using namespace std::chrono; |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 575 | microseconds usec{seconds(selDeviceTime)}; |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 576 | |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 577 | try |
| 578 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 579 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
shamim ali | 071d00c | 2022-03-02 15:42:46 +0530 | [diff] [blame] | 580 | bool ntp = std::get<bool>( |
| 581 | ipmi::getDbusProperty(bus, SystemdTimeService, SystemdTimePath, |
| 582 | SystemdTimeInterface, "NTP")); |
| 583 | if (ntp) |
| 584 | { |
| 585 | return ipmi::responseCommandNotAvailable(); |
| 586 | } |
| 587 | |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 588 | auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH); |
Andrew Geissler | 6467ed2 | 2020-05-16 16:03:53 -0500 | [diff] [blame] | 589 | std::variant<uint64_t> value{(uint64_t)usec.count()}; |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 590 | |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 591 | // Set bmc time |
| 592 | auto method = bus.new_method_call(service.c_str(), BMC_TIME_PATH, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 593 | DBUS_PROPERTIES, "Set"); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 594 | |
| 595 | method.append(TIME_INTERFACE, PROPERTY_ELAPSED, value); |
| 596 | auto reply = bus.call(method); |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 597 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 598 | catch (const InternalFailure& e) |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 599 | { |
George Liu | 51856e6 | 2024-07-17 19:46:03 +0800 | [diff] [blame] | 600 | lg2::error("Internal Failure: {ERROR}", "ERROR", e); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 601 | return ipmi::responseUnspecifiedError(); |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 602 | } |
Tom Joseph | 30fd0a1 | 2019-09-24 06:53:22 +0530 | [diff] [blame] | 603 | catch (const std::exception& e) |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 604 | { |
George Liu | 51856e6 | 2024-07-17 19:46:03 +0800 | [diff] [blame] | 605 | lg2::error("exception message: {ERROR}", "ERROR", e); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 606 | return ipmi::responseUnspecifiedError(); |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 607 | } |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 608 | |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 609 | return ipmi::responseSuccess(); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 610 | } |
| 611 | |
Xiaochao Ma | f020c44 | 2022-10-31 11:09:38 +0800 | [diff] [blame] | 612 | /** @brief implements the get SEL timezone command |
| 613 | * @returns IPMI completion code plus response data |
| 614 | * -current timezone |
| 615 | */ |
| 616 | ipmi::RspType<int16_t> ipmiStorageGetSelTimeUtcOffset() |
| 617 | { |
| 618 | time_t timep; |
| 619 | struct tm* gmTime; |
| 620 | struct tm* localTime; |
| 621 | |
| 622 | time(&timep); |
| 623 | localTime = localtime(&timep); |
| 624 | auto validLocalTime = mktime(localTime); |
| 625 | gmTime = gmtime(&timep); |
| 626 | auto validGmTime = mktime(gmTime); |
| 627 | auto timeEquation = (validLocalTime - validGmTime) / 60; |
| 628 | |
| 629 | return ipmi::responseSuccess(timeEquation); |
| 630 | } |
| 631 | |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 632 | /** @brief implements the reserve SEL command |
| 633 | * @returns IPMI completion code plus response data |
| 634 | * - SEL reservation ID. |
| 635 | */ |
| 636 | ipmi::RspType<uint16_t> ipmiStorageReserveSel() |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 637 | { |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 638 | return ipmi::responseSuccess(reserveSel()); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 639 | } |
| 640 | |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 641 | /** @brief implements the Add SEL entry command |
| 642 | * @request |
| 643 | * |
| 644 | * - recordID ID used for SEL Record access |
| 645 | * - recordType Record Type |
| 646 | * - timeStamp Time when event was logged. LS byte first |
| 647 | * - generatorID software ID if event was generated from |
| 648 | * system software |
| 649 | * - evmRev event message format version |
| 650 | * - sensorType sensor type code for service that generated |
| 651 | * the event |
| 652 | * - sensorNumber number of sensors that generated the event |
| 653 | * - eventDir event dir |
| 654 | * - eventData event data field contents |
| 655 | * |
| 656 | * @returns ipmi completion code plus response data |
| 657 | * - RecordID of the Added SEL entry |
| 658 | */ |
| 659 | ipmi::RspType<uint16_t // recordID of the Added SEL entry |
| 660 | > |
Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 661 | ipmiStorageAddSEL(uint16_t recordID, uint8_t recordType, |
| 662 | [[maybe_unused]] uint32_t timeStamp, uint16_t generatorID, |
Patrick Williams | 32aece1 | 2025-01-24 10:06:55 -0500 | [diff] [blame] | 663 | [[maybe_unused]] uint8_t evmRev, |
| 664 | [[maybe_unused]] uint8_t sensorType, uint8_t sensorNumber, |
| 665 | uint8_t eventDir, |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 666 | std::array<uint8_t, eventDataSize> eventData) |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 667 | { |
Lotus Xu | 57d3557 | 2021-01-24 11:13:13 +0800 | [diff] [blame] | 668 | std::string objpath; |
| 669 | static constexpr auto systemRecordType = 0x02; |
Patrick Williams | 32aece1 | 2025-01-24 10:06:55 -0500 | [diff] [blame] | 670 | #ifdef OPEN_POWER_SUPPORT |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 671 | // Hostboot sends SEL with OEM record type 0xDE to indicate that there is |
| 672 | // a maintenance procedure associated with eSEL record. |
| 673 | static constexpr auto procedureType = 0xDE; |
Patrick Williams | 32aece1 | 2025-01-24 10:06:55 -0500 | [diff] [blame] | 674 | #endif |
Lotus Xu | 57d3557 | 2021-01-24 11:13:13 +0800 | [diff] [blame] | 675 | cancelSELReservation(); |
| 676 | if (recordType == systemRecordType) |
| 677 | { |
Lotus Xu | 57d3557 | 2021-01-24 11:13:13 +0800 | [diff] [blame] | 678 | for (const auto& it : invSensors) |
| 679 | { |
| 680 | if (it.second.sensorID == sensorNumber) |
| 681 | { |
| 682 | objpath = it.first; |
| 683 | break; |
| 684 | } |
| 685 | } |
| 686 | auto selDataStr = ipmi::sel::toHexStr(eventData); |
| 687 | |
| 688 | bool assert = (eventDir & 0x80) ? false : true; |
| 689 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 690 | recordID = report<SELCreated>( |
| 691 | Created::RECORD_TYPE(recordType), |
| 692 | Created::GENERATOR_ID(generatorID), |
| 693 | Created::SENSOR_DATA(selDataStr.c_str()), |
| 694 | Created::EVENT_DIR(assert), Created::SENSOR_PATH(objpath.c_str())); |
Lotus Xu | 57d3557 | 2021-01-24 11:13:13 +0800 | [diff] [blame] | 695 | } |
Patrick Williams | 768730d | 2023-09-06 16:27:20 -0500 | [diff] [blame] | 696 | #ifdef OPEN_POWER_SUPPORT |
Lotus Xu | 57d3557 | 2021-01-24 11:13:13 +0800 | [diff] [blame] | 697 | else if (recordType == procedureType) |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 698 | { |
| 699 | // In the OEM record type 0xDE, byte 11 in the SEL record indicate the |
| 700 | // procedure number. |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 701 | createProcedureLogEntry(sensorType); |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 702 | } |
Patrick Williams | 768730d | 2023-09-06 16:27:20 -0500 | [diff] [blame] | 703 | #endif |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 704 | |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 705 | return ipmi::responseSuccess(recordID); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 706 | } |
| 707 | |
Konstantin Aladyshev | 69e3cd4 | 2021-11-26 16:46:17 +0300 | [diff] [blame] | 708 | bool isFruPresent(ipmi::Context::ptr& ctx, const std::string& fruPath) |
Kirill Pakhomov | fa6e209 | 2020-04-24 18:57:15 +0300 | [diff] [blame] | 709 | { |
| 710 | using namespace ipmi::fru; |
| 711 | |
Konstantin Aladyshev | 69e3cd4 | 2021-11-26 16:46:17 +0300 | [diff] [blame] | 712 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 713 | boost::system::error_code ec = |
| 714 | getService(ctx, invItemInterface, invObjPath + fruPath, service); |
Konstantin Aladyshev | 69e3cd4 | 2021-11-26 16:46:17 +0300 | [diff] [blame] | 715 | if (!ec) |
| 716 | { |
| 717 | bool result; |
| 718 | ec = ipmi::getDbusProperty(ctx, service, invObjPath + fruPath, |
| 719 | invItemInterface, itemPresentProp, result); |
| 720 | if (!ec) |
| 721 | { |
| 722 | return result; |
| 723 | } |
| 724 | } |
Konstantin Aladyshev | c7e4b04 | 2021-12-24 15:30:47 +0300 | [diff] [blame] | 725 | |
| 726 | ipmi::ObjectValueTree managedObjects; |
Nan Zhou | 947da1b | 2022-09-20 20:40:59 +0000 | [diff] [blame] | 727 | ec = getManagedObjects(ctx, "xyz.openbmc_project.EntityManager", |
| 728 | "/xyz/openbmc_project/inventory", managedObjects); |
Konstantin Aladyshev | c7e4b04 | 2021-12-24 15:30:47 +0300 | [diff] [blame] | 729 | if (!ec) |
| 730 | { |
| 731 | auto connection = managedObjects.find(fruPath); |
| 732 | if (connection != managedObjects.end()) |
| 733 | { |
| 734 | return true; |
| 735 | } |
| 736 | } |
| 737 | |
Konstantin Aladyshev | 69e3cd4 | 2021-11-26 16:46:17 +0300 | [diff] [blame] | 738 | return false; |
Kirill Pakhomov | fa6e209 | 2020-04-24 18:57:15 +0300 | [diff] [blame] | 739 | } |
| 740 | |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 741 | /** @brief implements the get FRU Inventory Area Info command |
| 742 | * |
| 743 | * @returns IPMI completion code plus response data |
| 744 | * - FRU Inventory area size in bytes, |
| 745 | * - access bit |
| 746 | **/ |
| 747 | ipmi::RspType<uint16_t, // FRU Inventory area size in bytes, |
| 748 | uint8_t // access size (bytes / words) |
| 749 | > |
Konstantin Aladyshev | 69e3cd4 | 2021-11-26 16:46:17 +0300 | [diff] [blame] | 750 | ipmiStorageGetFruInvAreaInfo(ipmi::Context::ptr ctx, uint8_t fruID) |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 751 | { |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 752 | auto iter = frus.find(fruID); |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 753 | if (iter == frus.end()) |
| 754 | { |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 755 | return ipmi::responseSensorInvalid(); |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 756 | } |
| 757 | |
Kirill Pakhomov | fa6e209 | 2020-04-24 18:57:15 +0300 | [diff] [blame] | 758 | auto path = iter->second[0].path; |
Konstantin Aladyshev | 69e3cd4 | 2021-11-26 16:46:17 +0300 | [diff] [blame] | 759 | if (!isFruPresent(ctx, path)) |
Kirill Pakhomov | fa6e209 | 2020-04-24 18:57:15 +0300 | [diff] [blame] | 760 | { |
| 761 | return ipmi::responseSensorInvalid(); |
| 762 | } |
| 763 | |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 764 | try |
| 765 | { |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 766 | return ipmi::responseSuccess( |
| 767 | static_cast<uint16_t>(getFruAreaData(fruID).size()), |
| 768 | static_cast<uint8_t>(AccessMode::bytes)); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 769 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 770 | catch (const InternalFailure& e) |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 771 | { |
George Liu | 51856e6 | 2024-07-17 19:46:03 +0800 | [diff] [blame] | 772 | lg2::error("Internal Failure: {ERROR}", "ERROR", e); |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 773 | return ipmi::responseUnspecifiedError(); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 774 | } |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 775 | } |
| 776 | |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 777 | /**@brief implements the Read FRU Data command |
| 778 | * @param fruDeviceId - FRU device ID. FFh = reserved |
| 779 | * @param offset - FRU inventory offset to read |
| 780 | * @param readCount - count to read |
| 781 | * |
| 782 | * @return IPMI completion code plus response data |
| 783 | * - returnCount - response data count. |
| 784 | * - data - response data |
| 785 | */ |
| 786 | ipmi::RspType<uint8_t, // count returned |
| 787 | std::vector<uint8_t>> // FRU data |
| 788 | ipmiStorageReadFruData(uint8_t fruDeviceId, uint16_t offset, |
| 789 | uint8_t readCount) |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 790 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 791 | if (fruDeviceId == 0xFF) |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 792 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 793 | return ipmi::responseInvalidFieldRequest(); |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 794 | } |
| 795 | |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 796 | auto iter = frus.find(fruDeviceId); |
| 797 | if (iter == frus.end()) |
| 798 | { |
| 799 | return ipmi::responseSensorInvalid(); |
| 800 | } |
| 801 | |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 802 | try |
| 803 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 804 | const auto& fruArea = getFruAreaData(fruDeviceId); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 805 | auto size = fruArea.size(); |
Nagaraju Goruganti | 7f2d7c9 | 2018-03-21 11:18:30 -0500 | [diff] [blame] | 806 | |
Tom Joseph | efcd68b | 2018-04-26 18:46:27 +0530 | [diff] [blame] | 807 | if (offset >= size) |
| 808 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 809 | return ipmi::responseParmOutOfRange(); |
Tom Joseph | efcd68b | 2018-04-26 18:46:27 +0530 | [diff] [blame] | 810 | } |
| 811 | |
Nagaraju Goruganti | 7f2d7c9 | 2018-03-21 11:18:30 -0500 | [diff] [blame] | 812 | // Write the count of response data. |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 813 | uint8_t returnCount; |
| 814 | if ((offset + readCount) <= size) |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 815 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 816 | returnCount = readCount; |
Nagaraju Goruganti | 7f2d7c9 | 2018-03-21 11:18:30 -0500 | [diff] [blame] | 817 | } |
| 818 | else |
| 819 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 820 | returnCount = size - offset; |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 821 | } |
Ratan Gupta | 2848d60 | 2018-01-31 20:39:20 +0530 | [diff] [blame] | 822 | |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 823 | std::vector<uint8_t> fruData((fruArea.begin() + offset), |
| 824 | (fruArea.begin() + offset + returnCount)); |
Ratan Gupta | 2848d60 | 2018-01-31 20:39:20 +0530 | [diff] [blame] | 825 | |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 826 | return ipmi::responseSuccess(returnCount, fruData); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 827 | } |
| 828 | catch (const InternalFailure& e) |
| 829 | { |
George Liu | 51856e6 | 2024-07-17 19:46:03 +0800 | [diff] [blame] | 830 | lg2::error("Internal Failure: {ERROR}", "ERROR", e); |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 831 | return ipmi::responseUnspecifiedError(); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 832 | } |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 833 | } |
| 834 | |
Pradeep Kumar | b60e840 | 2019-05-06 15:17:01 +0000 | [diff] [blame] | 835 | ipmi::RspType<uint8_t, // SDR version |
| 836 | uint16_t, // record count LS first |
| 837 | uint16_t, // free space in bytes, LS first |
| 838 | uint32_t, // addition timestamp LS first |
| 839 | uint32_t, // deletion timestamp LS first |
| 840 | uint8_t> // operation Support |
| 841 | ipmiGetRepositoryInfo() |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 842 | { |
Pradeep Kumar | b60e840 | 2019-05-06 15:17:01 +0000 | [diff] [blame] | 843 | constexpr uint8_t sdrVersion = 0x51; |
| 844 | constexpr uint16_t freeSpace = 0xFFFF; |
| 845 | constexpr uint32_t additionTimestamp = 0x0; |
| 846 | constexpr uint32_t deletionTimestamp = 0x0; |
| 847 | constexpr uint8_t operationSupport = 0; |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 848 | |
Willy Tu | 0ca3bfe | 2022-01-28 09:40:18 -0800 | [diff] [blame] | 849 | // Get SDR count. This returns the total number of SDRs in the device. |
| 850 | const auto& entityRecords = |
| 851 | ipmi::sensor::EntityInfoMapContainer::getContainer() |
| 852 | ->getIpmiEntityRecords(); |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 853 | uint16_t records = |
| 854 | ipmi::sensor::sensors.size() + frus.size() + entityRecords.size(); |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 855 | |
Pradeep Kumar | b60e840 | 2019-05-06 15:17:01 +0000 | [diff] [blame] | 856 | return ipmi::responseSuccess(sdrVersion, records, freeSpace, |
| 857 | additionTimestamp, deletionTimestamp, |
| 858 | operationSupport); |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 859 | } |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 860 | |
George Liu | 5087b07 | 2025-03-11 19:28:17 +0800 | [diff] [blame] | 861 | void registerNetFnStorageFunctions() |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 862 | { |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 863 | selCacheMapInitialized = false; |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 864 | initSELCache(); |
Willy Tu | d351a72 | 2021-08-12 14:33:40 -0700 | [diff] [blame] | 865 | // Handlers with dbus-sdr handler implementation. |
| 866 | // Do not register the hander if it dynamic sensors stack is used. |
| 867 | |
| 868 | #ifndef FEATURE_DYNAMIC_SENSORS |
Thang Tran | 292c917 | 2023-06-26 10:03:04 +0700 | [diff] [blame] | 869 | |
| 870 | #ifndef FEATURE_DYNAMIC_STORAGES_ONLY |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 871 | // <Get SEL Info> |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 872 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 873 | ipmi::storage::cmdGetSelInfo, ipmi::Privilege::User, |
| 874 | ipmiStorageGetSelInfo); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 875 | |
Xiaochao Ma | f020c44 | 2022-10-31 11:09:38 +0800 | [diff] [blame] | 876 | // <Get SEL Timezone> |
| 877 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 878 | ipmi::storage::cmdGetSelTimeUtcOffset, |
| 879 | ipmi::Privilege::User, |
| 880 | ipmiStorageGetSelTimeUtcOffset); |
| 881 | |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 882 | // <Get SEL Entry> |
George Liu | e759270 | 2025-07-03 15:48:02 +0800 | [diff] [blame] | 883 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 884 | ipmi::storage::cmdGetSelEntry, ipmi::Privilege::User, |
| 885 | getSELEntry); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 886 | |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 887 | // <Delete SEL Entry> |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 888 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 889 | ipmi::storage::cmdDeleteSelEntry, |
| 890 | ipmi::Privilege::Operator, deleteSELEntry); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 891 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 892 | // <Add SEL Entry> |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 893 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 894 | ipmi::storage::cmdAddSelEntry, |
| 895 | ipmi::Privilege::Operator, ipmiStorageAddSEL); |
| 896 | |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 897 | // <Clear SEL> |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 898 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 899 | ipmi::storage::cmdClearSel, ipmi::Privilege::Operator, |
| 900 | clearSEL); |
| 901 | |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 902 | // <Get FRU Inventory Area Info> |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 903 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 904 | ipmi::storage::cmdGetFruInventoryAreaInfo, |
| 905 | ipmi::Privilege::User, ipmiStorageGetFruInvAreaInfo); |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 906 | |
Jason M. Bills | b5248c9 | 2019-06-24 15:53:08 -0700 | [diff] [blame] | 907 | // <READ FRU Data> |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 908 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 909 | ipmi::storage::cmdReadFruData, |
| 910 | ipmi::Privilege::Operator, ipmiStorageReadFruData); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 911 | |
Thang Tran | 292c917 | 2023-06-26 10:03:04 +0700 | [diff] [blame] | 912 | #endif // FEATURE_DYNAMIC_STORAGES_ONLY |
| 913 | |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 914 | // <Get Repository Info> |
Pradeep Kumar | b60e840 | 2019-05-06 15:17:01 +0000 | [diff] [blame] | 915 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 916 | ipmi::storage::cmdGetSdrRepositoryInfo, |
| 917 | ipmi::Privilege::User, ipmiGetRepositoryInfo); |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 918 | |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 919 | // <Reserve SDR Repository> |
jayaprakash Mutyala | d957823 | 2019-05-13 20:22:50 +0000 | [diff] [blame] | 920 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 921 | ipmi::storage::cmdReserveSdrRepository, |
| 922 | ipmi::Privilege::User, ipmiSensorReserveSdr); |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 923 | |
| 924 | // <Get SDR> |
George Liu | ae30d81 | 2025-04-03 09:56:47 +0800 | [diff] [blame] | 925 | ipmi_register_callback(ipmi::netFnStorage, ipmi::storage::cmdGetSdr, |
| 926 | nullptr, ipmi_sen_get_sdr, PRIVILEGE_USER); |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 927 | |
Willy Tu | d351a72 | 2021-08-12 14:33:40 -0700 | [diff] [blame] | 928 | #endif |
| 929 | |
| 930 | // Common Handers used by both implementation. |
| 931 | |
| 932 | // <Reserve SEL> |
| 933 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 934 | ipmi::storage::cmdReserveSel, ipmi::Privilege::User, |
| 935 | ipmiStorageReserveSel); |
| 936 | |
Thang Tran | dbf66e1 | 2023-09-21 13:07:24 +0700 | [diff] [blame] | 937 | // <Get SEL Time> |
| 938 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 939 | ipmi::storage::cmdGetSelTime, ipmi::Privilege::User, |
| 940 | ipmiStorageGetSelTime); |
| 941 | |
| 942 | // <Set SEL Time> |
| 943 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 944 | ipmi::storage::cmdSetSelTime, |
| 945 | ipmi::Privilege::Operator, ipmiStorageSetSelTime); |
| 946 | |
Marri Devender Rao | 908f750 | 2017-07-10 01:49:54 -0500 | [diff] [blame] | 947 | ipmi::fru::registerCallbackHandler(); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 948 | return; |
| 949 | } |