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> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 20 | #include <phosphor-logging/elog-errors.hpp> |
| 21 | #include <phosphor-logging/log.hpp> |
| 22 | #include <sdbusplus/server.hpp> |
| 23 | #include <string> |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 24 | #include <variant> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 25 | #include <xyz/openbmc_project/Common/error.hpp> |
| 26 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 27 | void register_netfn_storage_functions() __attribute__((constructor)); |
| 28 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 29 | unsigned int g_sel_time = 0xFFFFFFFF; |
Patrick Venture | db0cbe6 | 2019-09-09 14:47:22 -0700 | [diff] [blame] | 30 | namespace ipmi |
| 31 | { |
| 32 | namespace sensor |
| 33 | { |
| 34 | extern const IdInfoMap sensors; |
| 35 | } // namespace sensor |
| 36 | } // namespace ipmi |
| 37 | |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 38 | extern const FruMap frus; |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 39 | constexpr uint8_t eventDataSize = 3; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 40 | namespace |
| 41 | { |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 42 | constexpr auto TIME_INTERFACE = "xyz.openbmc_project.Time.EpochTime"; |
| 43 | constexpr auto HOST_TIME_PATH = "/xyz/openbmc_project/time/host"; |
| 44 | constexpr auto DBUS_PROPERTIES = "org.freedesktop.DBus.Properties"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 45 | constexpr auto PROPERTY_ELAPSED = "Elapsed"; |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 46 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 47 | } // namespace |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 48 | |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 49 | namespace cache |
| 50 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 51 | /* |
| 52 | * This cache contains the object paths of the logging entries sorted in the |
| 53 | * order of the filename(numeric order). The cache is initialized by |
| 54 | * invoking readLoggingObjectPaths with the cache as the parameter. The |
| 55 | * cache is invoked in the execution of the Get SEL info and Delete SEL |
| 56 | * entry command. The Get SEL Info command is typically invoked before the |
| 57 | * Get SEL entry command, so the cache is utilized for responding to Get SEL |
| 58 | * entry command. The cache is invalidated by clearing after Delete SEL |
| 59 | * entry and Clear SEL command. |
| 60 | */ |
| 61 | ipmi::sel::ObjectPaths paths; |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 62 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 63 | } // namespace cache |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 64 | |
| 65 | using InternalFailure = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 66 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 67 | using namespace phosphor::logging; |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 68 | using namespace ipmi::fru; |
| 69 | |
| 70 | /** |
| 71 | * @enum Device access mode |
| 72 | */ |
| 73 | enum class AccessMode |
| 74 | { |
| 75 | bytes, ///< Device is accessed by bytes |
| 76 | words ///< Device is accessed by words |
| 77 | }; |
| 78 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 79 | ipmi_ret_t ipmi_storage_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 80 | ipmi_request_t request, |
| 81 | ipmi_response_t response, |
| 82 | ipmi_data_len_t data_len, |
| 83 | ipmi_context_t context) |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 84 | { |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 85 | // Status code. |
Nan Li | 70aa8d9 | 2016-08-29 00:11:10 +0800 | [diff] [blame] | 86 | ipmi_ret_t rc = IPMI_CC_INVALID; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 87 | *data_len = 0; |
| 88 | return rc; |
| 89 | } |
| 90 | |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 91 | /** @brief implements the get SEL Info command |
| 92 | * @returns IPMI completion code plus response data |
| 93 | * - selVersion - SEL revision |
| 94 | * - entries - Number of log entries in SEL. |
| 95 | * - freeSpace - Free Space in bytes. |
| 96 | * - addTimeStamp - Most recent addition timestamp |
| 97 | * - eraseTimeStamp - Most recent erase timestamp |
| 98 | * - operationSupport - Reserve & Delete SEL operations supported |
| 99 | */ |
| 100 | |
| 101 | ipmi::RspType<uint8_t, // SEL revision. |
| 102 | uint16_t, // number of log entries in SEL. |
| 103 | uint16_t, // free Space in bytes. |
| 104 | uint32_t, // most recent addition timestamp |
| 105 | uint32_t, // most recent erase timestamp. |
| 106 | |
| 107 | bool, // SEL allocation info supported |
| 108 | bool, // reserve SEL supported |
| 109 | bool, // partial Add SEL Entry supported |
| 110 | bool, // delete SEL supported |
| 111 | uint3_t, // reserved |
| 112 | bool // overflow flag |
| 113 | > |
| 114 | ipmiStorageGetSelInfo() |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 115 | { |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 116 | uint16_t entries = 0; |
| 117 | // Most recent addition timestamp. |
| 118 | uint32_t addTimeStamp = ipmi::sel::invalidTimeStamp; |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 119 | |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 120 | try |
| 121 | { |
| 122 | ipmi::sel::readLoggingObjectPaths(cache::paths); |
| 123 | } |
| 124 | catch (const sdbusplus::exception::SdBusError& e) |
| 125 | { |
| 126 | // No action if reading log objects have failed for this command. |
| 127 | // readLoggingObjectPaths will throw exception if there are no log |
| 128 | // entries. The command will be responded with number of SEL entries |
| 129 | // as 0. |
| 130 | } |
| 131 | |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 132 | if (!cache::paths.empty()) |
| 133 | { |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 134 | entries = static_cast<uint16_t>(cache::paths.size()); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 135 | |
| 136 | try |
| 137 | { |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 138 | addTimeStamp = static_cast<uint32_t>( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 139 | (ipmi::sel::getEntryTimeStamp(cache::paths.back()).count())); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 140 | } |
| 141 | catch (InternalFailure& e) |
| 142 | { |
| 143 | } |
| 144 | catch (const std::runtime_error& e) |
| 145 | { |
| 146 | log<level::ERR>(e.what()); |
| 147 | } |
| 148 | } |
| 149 | |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 150 | constexpr uint8_t selVersion = ipmi::sel::selVersion; |
| 151 | constexpr uint16_t freeSpace = 0xFFFF; |
| 152 | constexpr uint32_t eraseTimeStamp = ipmi::sel::invalidTimeStamp; |
| 153 | constexpr uint3_t reserved{0}; |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 154 | |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 155 | return ipmi::responseSuccess( |
| 156 | selVersion, entries, freeSpace, addTimeStamp, eraseTimeStamp, |
| 157 | ipmi::sel::operationSupport::getSelAllocationInfo, |
| 158 | ipmi::sel::operationSupport::reserveSel, |
| 159 | ipmi::sel::operationSupport::partialAddSelEntry, |
| 160 | ipmi::sel::operationSupport::deleteSel, reserved, |
| 161 | ipmi::sel::operationSupport::overflow); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 162 | } |
| 163 | |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 164 | ipmi_ret_t getSELEntry(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 165 | ipmi_request_t request, ipmi_response_t response, |
| 166 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 167 | { |
Jason M. Bills | 851acb1 | 2019-02-04 14:06:57 -0800 | [diff] [blame] | 168 | if (*data_len != sizeof(ipmi::sel::GetSELEntryRequest)) |
| 169 | { |
| 170 | *data_len = 0; |
| 171 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 172 | } |
| 173 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 174 | auto requestData = |
| 175 | reinterpret_cast<const ipmi::sel::GetSELEntryRequest*>(request); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 176 | |
| 177 | if (requestData->reservationID != 0) |
| 178 | { |
Jason M. Bills | 13e67c8 | 2018-09-10 14:12:16 -0700 | [diff] [blame] | 179 | if (!checkSELReservation(requestData->reservationID)) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 180 | { |
| 181 | *data_len = 0; |
| 182 | return IPMI_CC_INVALID_RESERVATION_ID; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | if (cache::paths.empty()) |
| 187 | { |
| 188 | *data_len = 0; |
| 189 | return IPMI_CC_SENSOR_INVALID; |
| 190 | } |
| 191 | |
| 192 | ipmi::sel::ObjectPaths::const_iterator iter; |
| 193 | |
| 194 | // Check for the requested SEL Entry. |
| 195 | if (requestData->selRecordID == ipmi::sel::firstEntry) |
| 196 | { |
| 197 | iter = cache::paths.begin(); |
| 198 | } |
| 199 | else if (requestData->selRecordID == ipmi::sel::lastEntry) |
| 200 | { |
| 201 | iter = cache::paths.end(); |
| 202 | } |
| 203 | else |
| 204 | { |
| 205 | std::string objPath = std::string(ipmi::sel::logBasePath) + "/" + |
| 206 | std::to_string(requestData->selRecordID); |
| 207 | |
| 208 | iter = std::find(cache::paths.begin(), cache::paths.end(), objPath); |
| 209 | if (iter == cache::paths.end()) |
| 210 | { |
| 211 | *data_len = 0; |
| 212 | return IPMI_CC_SENSOR_INVALID; |
| 213 | } |
| 214 | } |
| 215 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 216 | ipmi::sel::GetSELEntryResponse record{}; |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 217 | |
| 218 | // Convert the log entry into SEL record. |
| 219 | try |
| 220 | { |
| 221 | record = ipmi::sel::convertLogEntrytoSEL(*iter); |
| 222 | } |
| 223 | catch (InternalFailure& e) |
| 224 | { |
| 225 | *data_len = 0; |
| 226 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 227 | } |
| 228 | catch (const std::runtime_error& e) |
| 229 | { |
| 230 | log<level::ERR>(e.what()); |
| 231 | *data_len = 0; |
| 232 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 233 | } |
| 234 | |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 235 | // Identify the next SEL record ID |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 236 | if (iter != cache::paths.end()) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 237 | { |
| 238 | ++iter; |
| 239 | if (iter == cache::paths.end()) |
| 240 | { |
| 241 | record.nextRecordID = ipmi::sel::lastEntry; |
| 242 | } |
| 243 | else |
| 244 | { |
Vernon Mauery | 185b9f8 | 2018-07-20 10:52:36 -0700 | [diff] [blame] | 245 | namespace fs = std::filesystem; |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 246 | fs::path path(*iter); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 247 | record.nextRecordID = static_cast<uint16_t>( |
| 248 | std::stoul(std::string(path.filename().c_str()))); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | else |
| 252 | { |
| 253 | record.nextRecordID = ipmi::sel::lastEntry; |
| 254 | } |
| 255 | |
| 256 | if (requestData->readLength == ipmi::sel::entireRecord) |
| 257 | { |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 258 | std::memcpy(response, &record, sizeof(record)); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 259 | *data_len = sizeof(record); |
| 260 | } |
| 261 | else |
| 262 | { |
| 263 | if (requestData->offset >= ipmi::sel::selRecordSize || |
| 264 | requestData->readLength > ipmi::sel::selRecordSize) |
| 265 | { |
| 266 | *data_len = 0; |
| 267 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 268 | } |
| 269 | |
| 270 | auto diff = ipmi::sel::selRecordSize - requestData->offset; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 271 | auto readLength = |
| 272 | std::min(diff, static_cast<int>(requestData->readLength)); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 273 | |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 274 | std::memcpy(response, &record.nextRecordID, |
| 275 | sizeof(record.nextRecordID)); |
| 276 | std::memcpy(static_cast<uint8_t*>(response) + |
| 277 | sizeof(record.nextRecordID), |
| 278 | &record.recordID + requestData->offset, readLength); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 279 | *data_len = sizeof(record.nextRecordID) + readLength; |
| 280 | } |
| 281 | |
| 282 | return IPMI_CC_OK; |
| 283 | } |
| 284 | |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 285 | /** @brief implements the delete SEL entry command |
| 286 | * @request |
| 287 | * - reservationID; // reservation ID. |
| 288 | * - selRecordID; // SEL record ID. |
| 289 | * |
| 290 | * @returns ipmi completion code plus response data |
| 291 | * - Record ID of the deleted record |
| 292 | */ |
| 293 | ipmi::RspType<uint16_t // deleted record ID |
| 294 | > |
| 295 | deleteSELEntry(uint16_t reservationID, uint16_t selRecordID) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 296 | { |
Jason M. Bills | 851acb1 | 2019-02-04 14:06:57 -0800 | [diff] [blame] | 297 | |
Brad Bishop | 1a4117b | 2018-11-21 15:48:18 -0500 | [diff] [blame] | 298 | namespace fs = std::filesystem; |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 299 | |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 300 | if (!checkSELReservation(reservationID)) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 301 | { |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 302 | return ipmi::responseInvalidReservationId(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 303 | } |
| 304 | |
Jason M. Bills | 13e67c8 | 2018-09-10 14:12:16 -0700 | [diff] [blame] | 305 | // Per the IPMI spec, need to cancel the reservation when a SEL entry is |
| 306 | // deleted |
| 307 | cancelSELReservation(); |
| 308 | |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 309 | try |
| 310 | { |
| 311 | ipmi::sel::readLoggingObjectPaths(cache::paths); |
| 312 | } |
| 313 | catch (const sdbusplus::exception::SdBusError& e) |
| 314 | { |
| 315 | // readLoggingObjectPaths will throw exception if there are no error |
| 316 | // log entries. |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 317 | return ipmi::responseSensorInvalid(); |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 318 | } |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 319 | |
| 320 | if (cache::paths.empty()) |
| 321 | { |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 322 | return ipmi::responseSensorInvalid(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | ipmi::sel::ObjectPaths::const_iterator iter; |
| 326 | uint16_t delRecordID = 0; |
| 327 | |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 328 | if (selRecordID == ipmi::sel::firstEntry) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 329 | { |
| 330 | iter = cache::paths.begin(); |
| 331 | fs::path path(*iter); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 332 | delRecordID = static_cast<uint16_t>( |
| 333 | std::stoul(std::string(path.filename().c_str()))); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 334 | } |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 335 | else if (selRecordID == ipmi::sel::lastEntry) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 336 | { |
| 337 | iter = cache::paths.end(); |
| 338 | fs::path path(*iter); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 339 | delRecordID = static_cast<uint16_t>( |
| 340 | std::stoul(std::string(path.filename().c_str()))); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 341 | } |
| 342 | else |
| 343 | { |
| 344 | std::string objPath = std::string(ipmi::sel::logBasePath) + "/" + |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 345 | std::to_string(selRecordID); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 346 | |
| 347 | iter = std::find(cache::paths.begin(), cache::paths.end(), objPath); |
| 348 | if (iter == cache::paths.end()) |
| 349 | { |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 350 | return ipmi::responseSensorInvalid(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 351 | } |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 352 | delRecordID = selRecordID; |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 356 | std::string service; |
| 357 | |
| 358 | try |
| 359 | { |
| 360 | service = ipmi::getService(bus, ipmi::sel::logDeleteIntf, *iter); |
| 361 | } |
| 362 | catch (const std::runtime_error& e) |
| 363 | { |
| 364 | log<level::ERR>(e.what()); |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 365 | return ipmi::responseUnspecifiedError(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 366 | } |
| 367 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 368 | auto methodCall = bus.new_method_call(service.c_str(), (*iter).c_str(), |
| 369 | ipmi::sel::logDeleteIntf, "Delete"); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 370 | auto reply = bus.call(methodCall); |
| 371 | if (reply.is_method_error()) |
| 372 | { |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 373 | return ipmi::responseUnspecifiedError(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | // Invalidate the cache of dbus entry objects. |
| 377 | cache::paths.clear(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 378 | |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 379 | return ipmi::responseSuccess(delRecordID); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 380 | } |
| 381 | |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 382 | /** @brief implements the Clear SEL command |
| 383 | * @request |
| 384 | * - reservationID // Reservation ID. |
| 385 | * - clr // char array { 'C'(0x43h), 'L'(0x4Ch), 'R'(0x52h) } |
| 386 | * - eraseOperation; // requested operation. |
| 387 | * |
| 388 | * @returns ipmi completion code plus response data |
| 389 | * - erase status |
| 390 | */ |
| 391 | |
| 392 | ipmi::RspType<uint8_t // erase status |
| 393 | > |
| 394 | clearSEL(uint16_t reservationID, const std::array<char, 3>& clr, |
| 395 | uint8_t eraseOperation) |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 396 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 397 | static constexpr std::array<char, 3> clrOk = {'C', 'L', 'R'}; |
| 398 | if (clr != clrOk) |
Jason M. Bills | 851acb1 | 2019-02-04 14:06:57 -0800 | [diff] [blame] | 399 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 400 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 851acb1 | 2019-02-04 14:06:57 -0800 | [diff] [blame] | 401 | } |
| 402 | |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 403 | if (!checkSELReservation(reservationID)) |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 404 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 405 | return ipmi::responseInvalidReservationId(); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 406 | } |
| 407 | |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 408 | /* |
| 409 | * Erasure status cannot be fetched from DBUS, so always return erasure |
| 410 | * status as `erase completed`. |
| 411 | */ |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 412 | if (eraseOperation == ipmi::sel::getEraseStatus) |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 413 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 414 | return ipmi::responseSuccess( |
| 415 | static_cast<uint8_t>(ipmi::sel::eraseComplete)); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 416 | } |
| 417 | |
Jason M. Bills | 13e67c8 | 2018-09-10 14:12:16 -0700 | [diff] [blame] | 418 | // Per the IPMI spec, need to cancel any reservation when the SEL is cleared |
| 419 | cancelSELReservation(); |
| 420 | |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 421 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 422 | ipmi::sel::ObjectPaths objectPaths; |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 423 | auto depth = 0; |
| 424 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 425 | auto mapperCall = |
| 426 | bus.new_method_call(ipmi::sel::mapperBusName, ipmi::sel::mapperObjPath, |
| 427 | ipmi::sel::mapperIntf, "GetSubTreePaths"); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 428 | mapperCall.append(ipmi::sel::logBasePath); |
| 429 | mapperCall.append(depth); |
| 430 | mapperCall.append(ipmi::sel::ObjectPaths({ipmi::sel::logEntryIntf})); |
| 431 | |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 432 | try |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 433 | { |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 434 | auto reply = bus.call(mapperCall); |
| 435 | if (reply.is_method_error()) |
| 436 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 437 | return ipmi::responseSuccess( |
| 438 | static_cast<uint8_t>(ipmi::sel::eraseComplete)); |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 439 | } |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 440 | |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 441 | reply.read(objectPaths); |
| 442 | if (objectPaths.empty()) |
| 443 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 444 | return ipmi::responseSuccess( |
| 445 | static_cast<uint8_t>(ipmi::sel::eraseComplete)); |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 446 | } |
| 447 | } |
| 448 | catch (const sdbusplus::exception::SdBusError& e) |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 449 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 450 | return ipmi::responseSuccess( |
| 451 | static_cast<uint8_t>(ipmi::sel::eraseComplete)); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | std::string service; |
| 455 | |
| 456 | try |
| 457 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 458 | service = ipmi::getService(bus, ipmi::sel::logDeleteIntf, |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 459 | objectPaths.front()); |
| 460 | } |
| 461 | catch (const std::runtime_error& e) |
| 462 | { |
| 463 | log<level::ERR>(e.what()); |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 464 | return ipmi::responseUnspecifiedError(); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | for (const auto& iter : objectPaths) |
| 468 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 469 | auto methodCall = bus.new_method_call( |
| 470 | service.c_str(), iter.c_str(), ipmi::sel::logDeleteIntf, "Delete"); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 471 | |
| 472 | auto reply = bus.call(methodCall); |
| 473 | if (reply.is_method_error()) |
| 474 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 475 | return ipmi::responseUnspecifiedError(); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | |
| 479 | // Invalidate the cache of dbus entry objects. |
| 480 | cache::paths.clear(); |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 481 | return ipmi::responseSuccess( |
| 482 | static_cast<uint8_t>(ipmi::sel::eraseComplete)); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 483 | } |
| 484 | |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 485 | /** @brief implements the get SEL time command |
| 486 | * @returns IPMI completion code plus response data |
| 487 | * -current time |
| 488 | */ |
| 489 | ipmi::RspType<uint32_t> // current time |
| 490 | ipmiStorageGetSelTime() |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 491 | { |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 492 | using namespace std::chrono; |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 493 | uint64_t host_time_usec = 0; |
Nagaraju Goruganti | 8960b7c | 2018-04-29 22:38:40 -0500 | [diff] [blame] | 494 | std::stringstream hostTime; |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 495 | |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 496 | try |
| 497 | { |
| 498 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 499 | auto service = ipmi::getService(bus, TIME_INTERFACE, HOST_TIME_PATH); |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 500 | std::variant<uint64_t> value; |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 501 | |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 502 | // Get host time |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 503 | auto method = bus.new_method_call(service.c_str(), HOST_TIME_PATH, |
| 504 | DBUS_PROPERTIES, "Get"); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 505 | |
| 506 | method.append(TIME_INTERFACE, PROPERTY_ELAPSED); |
| 507 | auto reply = bus.call(method); |
| 508 | if (reply.is_method_error()) |
| 509 | { |
| 510 | log<level::ERR>("Error getting time", |
| 511 | entry("SERVICE=%s", service.c_str()), |
| 512 | entry("PATH=%s", HOST_TIME_PATH)); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 513 | return ipmi::responseUnspecifiedError(); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 514 | } |
| 515 | reply.read(value); |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 516 | host_time_usec = std::get<uint64_t>(value); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 517 | } |
| 518 | catch (InternalFailure& e) |
| 519 | { |
| 520 | log<level::ERR>(e.what()); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 521 | return ipmi::responseUnspecifiedError(); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 522 | } |
Tom Joseph | 30fd0a1 | 2019-09-24 06:53:22 +0530 | [diff] [blame] | 523 | catch (const std::exception& e) |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 524 | { |
| 525 | log<level::ERR>(e.what()); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 526 | return ipmi::responseUnspecifiedError(); |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 527 | } |
| 528 | |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 529 | hostTime << "Host time:" |
| 530 | << duration_cast<seconds>(microseconds(host_time_usec)).count(); |
Nagaraju Goruganti | 8960b7c | 2018-04-29 22:38:40 -0500 | [diff] [blame] | 531 | log<level::DEBUG>(hostTime.str().c_str()); |
| 532 | |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 533 | // Time is really long int but IPMI wants just uint32. This works okay until |
| 534 | // the number of seconds since 1970 overflows uint32 size.. Still a whole |
| 535 | // lot of time here to even think about that. |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 536 | return ipmi::responseSuccess( |
| 537 | duration_cast<seconds>(microseconds(host_time_usec)).count()); |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 538 | } |
| 539 | |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 540 | /** @brief implements the set SEL time command |
| 541 | * @param selDeviceTime - epoch time |
| 542 | * -local time as the number of seconds from 00:00:00, January 1, 1970 |
| 543 | * @returns IPMI completion code |
| 544 | */ |
| 545 | ipmi::RspType<> ipmiStorageSetSelTime(uint32_t selDeviceTime) |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 546 | { |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 547 | using namespace std::chrono; |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 548 | microseconds usec{seconds(selDeviceTime)}; |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 549 | |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 550 | try |
| 551 | { |
| 552 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 553 | auto service = ipmi::getService(bus, TIME_INTERFACE, HOST_TIME_PATH); |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 554 | std::variant<uint64_t> value{usec.count()}; |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 555 | |
| 556 | // Set host time |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 557 | auto method = bus.new_method_call(service.c_str(), HOST_TIME_PATH, |
| 558 | DBUS_PROPERTIES, "Set"); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 559 | |
| 560 | method.append(TIME_INTERFACE, PROPERTY_ELAPSED, value); |
| 561 | auto reply = bus.call(method); |
| 562 | if (reply.is_method_error()) |
| 563 | { |
| 564 | log<level::ERR>("Error setting time", |
| 565 | entry("SERVICE=%s", service.c_str()), |
| 566 | entry("PATH=%s", HOST_TIME_PATH)); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 567 | return ipmi::responseUnspecifiedError(); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 568 | } |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 569 | } |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 570 | catch (InternalFailure& e) |
| 571 | { |
| 572 | log<level::ERR>(e.what()); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 573 | return ipmi::responseUnspecifiedError(); |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 574 | } |
Tom Joseph | 30fd0a1 | 2019-09-24 06:53:22 +0530 | [diff] [blame] | 575 | catch (const std::exception& e) |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 576 | { |
| 577 | log<level::ERR>(e.what()); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 578 | return ipmi::responseUnspecifiedError(); |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 579 | } |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 580 | |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 581 | return ipmi::responseSuccess(); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 582 | } |
| 583 | |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 584 | /** @brief implements the reserve SEL command |
| 585 | * @returns IPMI completion code plus response data |
| 586 | * - SEL reservation ID. |
| 587 | */ |
| 588 | ipmi::RspType<uint16_t> ipmiStorageReserveSel() |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 589 | { |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 590 | return ipmi::responseSuccess(reserveSel()); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 591 | } |
| 592 | |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 593 | /** @brief implements the Add SEL entry command |
| 594 | * @request |
| 595 | * |
| 596 | * - recordID ID used for SEL Record access |
| 597 | * - recordType Record Type |
| 598 | * - timeStamp Time when event was logged. LS byte first |
| 599 | * - generatorID software ID if event was generated from |
| 600 | * system software |
| 601 | * - evmRev event message format version |
| 602 | * - sensorType sensor type code for service that generated |
| 603 | * the event |
| 604 | * - sensorNumber number of sensors that generated the event |
| 605 | * - eventDir event dir |
| 606 | * - eventData event data field contents |
| 607 | * |
| 608 | * @returns ipmi completion code plus response data |
| 609 | * - RecordID of the Added SEL entry |
| 610 | */ |
| 611 | ipmi::RspType<uint16_t // recordID of the Added SEL entry |
| 612 | > |
| 613 | ipmiStorageAddSEL(uint16_t recordID, uint8_t recordType, uint32_t timeStamp, |
| 614 | uint16_t generatorID, uint8_t evmRev, uint8_t sensorType, |
| 615 | uint8_t sensorNumber, uint8_t eventDir, |
| 616 | std::array<uint8_t, eventDataSize> eventData) |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 617 | { |
Jason M. Bills | 13e67c8 | 2018-09-10 14:12:16 -0700 | [diff] [blame] | 618 | // Per the IPMI spec, need to cancel the reservation when a SEL entry is |
| 619 | // added |
| 620 | cancelSELReservation(); |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 621 | // Hostboot sends SEL with OEM record type 0xDE to indicate that there is |
| 622 | // a maintenance procedure associated with eSEL record. |
| 623 | static constexpr auto procedureType = 0xDE; |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 624 | if (recordType == procedureType) |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 625 | { |
| 626 | // In the OEM record type 0xDE, byte 11 in the SEL record indicate the |
| 627 | // procedure number. |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 628 | createProcedureLogEntry(sensorType); |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 629 | } |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 630 | |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 631 | return ipmi::responseSuccess(recordID); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 632 | } |
| 633 | |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 634 | /** @brief implements the get FRU Inventory Area Info command |
| 635 | * |
| 636 | * @returns IPMI completion code plus response data |
| 637 | * - FRU Inventory area size in bytes, |
| 638 | * - access bit |
| 639 | **/ |
| 640 | ipmi::RspType<uint16_t, // FRU Inventory area size in bytes, |
| 641 | uint8_t // access size (bytes / words) |
| 642 | > |
| 643 | ipmiStorageGetFruInvAreaInfo(uint8_t fruID) |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 644 | { |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 645 | |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 646 | auto iter = frus.find(fruID); |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 647 | if (iter == frus.end()) |
| 648 | { |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 649 | return ipmi::responseSensorInvalid(); |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 650 | } |
| 651 | |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 652 | try |
| 653 | { |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 654 | return ipmi::responseSuccess( |
| 655 | static_cast<uint16_t>(getFruAreaData(fruID).size()), |
| 656 | static_cast<uint8_t>(AccessMode::bytes)); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 657 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 658 | catch (const InternalFailure& e) |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 659 | { |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 660 | log<level::ERR>(e.what()); |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 661 | return ipmi::responseUnspecifiedError(); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 662 | } |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 663 | } |
| 664 | |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 665 | /**@brief implements the Read FRU Data command |
| 666 | * @param fruDeviceId - FRU device ID. FFh = reserved |
| 667 | * @param offset - FRU inventory offset to read |
| 668 | * @param readCount - count to read |
| 669 | * |
| 670 | * @return IPMI completion code plus response data |
| 671 | * - returnCount - response data count. |
| 672 | * - data - response data |
| 673 | */ |
| 674 | ipmi::RspType<uint8_t, // count returned |
| 675 | std::vector<uint8_t>> // FRU data |
| 676 | ipmiStorageReadFruData(uint8_t fruDeviceId, uint16_t offset, |
| 677 | uint8_t readCount) |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 678 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 679 | if (fruDeviceId == 0xFF) |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 680 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 681 | return ipmi::responseInvalidFieldRequest(); |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 682 | } |
| 683 | |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 684 | auto iter = frus.find(fruDeviceId); |
| 685 | if (iter == frus.end()) |
| 686 | { |
| 687 | return ipmi::responseSensorInvalid(); |
| 688 | } |
| 689 | |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 690 | try |
| 691 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 692 | const auto& fruArea = getFruAreaData(fruDeviceId); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 693 | auto size = fruArea.size(); |
Nagaraju Goruganti | 7f2d7c9 | 2018-03-21 11:18:30 -0500 | [diff] [blame] | 694 | |
Tom Joseph | efcd68b | 2018-04-26 18:46:27 +0530 | [diff] [blame] | 695 | if (offset >= size) |
| 696 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 697 | return ipmi::responseParmOutOfRange(); |
Tom Joseph | efcd68b | 2018-04-26 18:46:27 +0530 | [diff] [blame] | 698 | } |
| 699 | |
Nagaraju Goruganti | 7f2d7c9 | 2018-03-21 11:18:30 -0500 | [diff] [blame] | 700 | // Write the count of response data. |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 701 | uint8_t returnCount; |
| 702 | if ((offset + readCount) <= size) |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 703 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 704 | returnCount = readCount; |
Nagaraju Goruganti | 7f2d7c9 | 2018-03-21 11:18:30 -0500 | [diff] [blame] | 705 | } |
| 706 | else |
| 707 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 708 | returnCount = size - offset; |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 709 | } |
Ratan Gupta | 2848d60 | 2018-01-31 20:39:20 +0530 | [diff] [blame] | 710 | |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 711 | std::vector<uint8_t> fruData((fruArea.begin() + offset), |
| 712 | (fruArea.begin() + offset + returnCount)); |
Ratan Gupta | 2848d60 | 2018-01-31 20:39:20 +0530 | [diff] [blame] | 713 | |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 714 | return ipmi::responseSuccess(returnCount, fruData); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 715 | } |
| 716 | catch (const InternalFailure& e) |
| 717 | { |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 718 | log<level::ERR>(e.what()); |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 719 | return ipmi::responseUnspecifiedError(); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 720 | } |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 721 | } |
| 722 | |
Pradeep Kumar | b60e840 | 2019-05-06 15:17:01 +0000 | [diff] [blame] | 723 | ipmi::RspType<uint8_t, // SDR version |
| 724 | uint16_t, // record count LS first |
| 725 | uint16_t, // free space in bytes, LS first |
| 726 | uint32_t, // addition timestamp LS first |
| 727 | uint32_t, // deletion timestamp LS first |
| 728 | uint8_t> // operation Support |
| 729 | ipmiGetRepositoryInfo() |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 730 | { |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 731 | |
Pradeep Kumar | b60e840 | 2019-05-06 15:17:01 +0000 | [diff] [blame] | 732 | constexpr uint8_t sdrVersion = 0x51; |
| 733 | constexpr uint16_t freeSpace = 0xFFFF; |
| 734 | constexpr uint32_t additionTimestamp = 0x0; |
| 735 | constexpr uint32_t deletionTimestamp = 0x0; |
| 736 | constexpr uint8_t operationSupport = 0; |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 737 | |
Patrick Venture | db0cbe6 | 2019-09-09 14:47:22 -0700 | [diff] [blame] | 738 | uint16_t records = frus.size() + ipmi::sensor::sensors.size(); |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 739 | |
Pradeep Kumar | b60e840 | 2019-05-06 15:17:01 +0000 | [diff] [blame] | 740 | return ipmi::responseSuccess(sdrVersion, records, freeSpace, |
| 741 | additionTimestamp, deletionTimestamp, |
| 742 | operationSupport); |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 743 | } |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 744 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 745 | void register_netfn_storage_functions() |
| 746 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 747 | // <Wildcard Command> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 748 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_WILDCARD, NULL, |
| 749 | ipmi_storage_wildcard, PRIVILEGE_USER); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 750 | |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 751 | // <Get SEL Info> |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 752 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 753 | ipmi::storage::cmdGetSelInfo, ipmi::Privilege::User, |
| 754 | ipmiStorageGetSelInfo); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 755 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 756 | // <Get SEL Time> |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 757 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 758 | ipmi::storage::cmdGetSelTime, ipmi::Privilege::User, |
| 759 | ipmiStorageGetSelTime); |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 760 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 761 | // <Set SEL Time> |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 762 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 763 | ipmi::storage::cmdSetSelTime, |
| 764 | ipmi::Privilege::Operator, ipmiStorageSetSelTime); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 765 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 766 | // <Reserve SEL> |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 767 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 768 | ipmi::storage::cmdReserveSel, ipmi::Privilege::User, |
| 769 | ipmiStorageReserveSel); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 770 | // <Get SEL Entry> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 771 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY, NULL, |
| 772 | getSELEntry, PRIVILEGE_USER); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 773 | |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 774 | // <Delete SEL Entry> |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 775 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 776 | ipmi::storage::cmdDeleteSelEntry, |
| 777 | ipmi::Privilege::Operator, deleteSELEntry); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 778 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 779 | // <Add SEL Entry> |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 780 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 781 | ipmi::storage::cmdAddSelEntry, |
| 782 | ipmi::Privilege::Operator, ipmiStorageAddSEL); |
| 783 | |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 784 | // <Clear SEL> |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 785 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 786 | ipmi::storage::cmdClearSel, ipmi::Privilege::Operator, |
| 787 | clearSEL); |
| 788 | |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 789 | // <Get FRU Inventory Area Info> |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 790 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 791 | ipmi::storage::cmdGetFruInventoryAreaInfo, |
| 792 | ipmi::Privilege::User, ipmiStorageGetFruInvAreaInfo); |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 793 | |
Jason M. Bills | b5248c9 | 2019-06-24 15:53:08 -0700 | [diff] [blame] | 794 | // <READ FRU Data> |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 795 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 796 | ipmi::storage::cmdReadFruData, |
| 797 | ipmi::Privilege::Operator, ipmiStorageReadFruData); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 798 | |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 799 | // <Get Repository Info> |
Pradeep Kumar | b60e840 | 2019-05-06 15:17:01 +0000 | [diff] [blame] | 800 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 801 | ipmi::storage::cmdGetSdrRepositoryInfo, |
| 802 | ipmi::Privilege::User, ipmiGetRepositoryInfo); |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 803 | |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 804 | // <Reserve SDR Repository> |
jayaprakash Mutyala | d957823 | 2019-05-13 20:22:50 +0000 | [diff] [blame] | 805 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 806 | ipmi::storage::cmdReserveSdrRepository, |
| 807 | ipmi::Privilege::User, ipmiSensorReserveSdr); |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 808 | |
| 809 | // <Get SDR> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 810 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SDR, nullptr, |
| 811 | ipmi_sen_get_sdr, PRIVILEGE_USER); |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 812 | |
Marri Devender Rao | 908f750 | 2017-07-10 01:49:54 -0500 | [diff] [blame] | 813 | ipmi::fru::registerCallbackHandler(); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 814 | return; |
| 815 | } |