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