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