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