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