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