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 | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame^] | 18 | #include <phosphor-logging/elog-errors.hpp> |
| 19 | #include <phosphor-logging/log.hpp> |
| 20 | #include <sdbusplus/server.hpp> |
| 21 | #include <string> |
| 22 | #include <xyz/openbmc_project/Common/error.hpp> |
| 23 | |
Vernon Mauery | 185b9f8 | 2018-07-20 10:52:36 -0700 | [diff] [blame] | 24 | #if __has_include(<filesystem>) |
| 25 | #include <filesystem> |
| 26 | #elif __has_include(<experimental/filesystem>) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 27 | #include <experimental/filesystem> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 28 | namespace std |
| 29 | { |
| 30 | // splice experimental::filesystem into std |
| 31 | namespace filesystem = std::experimental::filesystem; |
| 32 | } // namespace std |
Vernon Mauery | 185b9f8 | 2018-07-20 10:52:36 -0700 | [diff] [blame] | 33 | #else |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 34 | #error filesystem not available |
Vernon Mauery | 185b9f8 | 2018-07-20 10:52:36 -0700 | [diff] [blame] | 35 | #endif |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 36 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 37 | void register_netfn_storage_functions() __attribute__((constructor)); |
| 38 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 39 | unsigned int g_sel_time = 0xFFFFFFFF; |
Nan Li | 36c0cb6 | 2016-03-31 11:16:08 +0800 | [diff] [blame] | 40 | extern unsigned short g_sel_reserve; |
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 | |
| 148 | memcpy(response, outPayload.data(), outPayload.size()); |
| 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 | { |
| 163 | if (g_sel_reserve != requestData->reservationID) |
| 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 | { |
| 242 | memcpy(response, &record, sizeof(record)); |
| 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 | |
| 258 | memcpy(response, &record.nextRecordID, sizeof(record.nextRecordID)); |
| 259 | memcpy(static_cast<uint8_t*>(response) + sizeof(record.nextRecordID), |
| 260 | &record.recordID + requestData->offset, readLength); |
| 261 | *data_len = sizeof(record.nextRecordID) + readLength; |
| 262 | } |
| 263 | |
| 264 | return IPMI_CC_OK; |
| 265 | } |
| 266 | |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 267 | ipmi_ret_t deleteSELEntry(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 268 | ipmi_request_t request, ipmi_response_t response, |
| 269 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 270 | { |
| 271 | namespace fs = std::experimental::filesystem; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 272 | auto requestData = |
| 273 | reinterpret_cast<const ipmi::sel::DeleteSELEntryRequest*>(request); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 274 | |
| 275 | if (g_sel_reserve != requestData->reservationID) |
| 276 | { |
| 277 | *data_len = 0; |
| 278 | return IPMI_CC_INVALID_RESERVATION_ID; |
| 279 | } |
| 280 | |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 281 | try |
| 282 | { |
| 283 | ipmi::sel::readLoggingObjectPaths(cache::paths); |
| 284 | } |
| 285 | catch (const sdbusplus::exception::SdBusError& e) |
| 286 | { |
| 287 | // readLoggingObjectPaths will throw exception if there are no error |
| 288 | // log entries. |
| 289 | *data_len = 0; |
| 290 | return IPMI_CC_SENSOR_INVALID; |
| 291 | } |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 292 | |
| 293 | if (cache::paths.empty()) |
| 294 | { |
| 295 | *data_len = 0; |
| 296 | return IPMI_CC_SENSOR_INVALID; |
| 297 | } |
| 298 | |
| 299 | ipmi::sel::ObjectPaths::const_iterator iter; |
| 300 | uint16_t delRecordID = 0; |
| 301 | |
| 302 | if (requestData->selRecordID == ipmi::sel::firstEntry) |
| 303 | { |
| 304 | iter = cache::paths.begin(); |
| 305 | fs::path path(*iter); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 306 | delRecordID = static_cast<uint16_t>( |
| 307 | std::stoul(std::string(path.filename().c_str()))); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 308 | } |
| 309 | else if (requestData->selRecordID == ipmi::sel::lastEntry) |
| 310 | { |
| 311 | iter = cache::paths.end(); |
| 312 | fs::path path(*iter); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 313 | delRecordID = static_cast<uint16_t>( |
| 314 | std::stoul(std::string(path.filename().c_str()))); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 315 | } |
| 316 | else |
| 317 | { |
| 318 | std::string objPath = std::string(ipmi::sel::logBasePath) + "/" + |
| 319 | std::to_string(requestData->selRecordID); |
| 320 | |
| 321 | iter = std::find(cache::paths.begin(), cache::paths.end(), objPath); |
| 322 | if (iter == cache::paths.end()) |
| 323 | { |
| 324 | *data_len = 0; |
| 325 | return IPMI_CC_SENSOR_INVALID; |
| 326 | } |
| 327 | delRecordID = requestData->selRecordID; |
| 328 | } |
| 329 | |
| 330 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 331 | std::string service; |
| 332 | |
| 333 | try |
| 334 | { |
| 335 | service = ipmi::getService(bus, ipmi::sel::logDeleteIntf, *iter); |
| 336 | } |
| 337 | catch (const std::runtime_error& e) |
| 338 | { |
| 339 | log<level::ERR>(e.what()); |
| 340 | *data_len = 0; |
| 341 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 342 | } |
| 343 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 344 | auto methodCall = bus.new_method_call(service.c_str(), (*iter).c_str(), |
| 345 | ipmi::sel::logDeleteIntf, "Delete"); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 346 | auto reply = bus.call(methodCall); |
| 347 | if (reply.is_method_error()) |
| 348 | { |
| 349 | *data_len = 0; |
| 350 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 351 | } |
| 352 | |
| 353 | // Invalidate the cache of dbus entry objects. |
| 354 | cache::paths.clear(); |
| 355 | memcpy(response, &delRecordID, sizeof(delRecordID)); |
| 356 | *data_len = sizeof(delRecordID); |
| 357 | |
| 358 | return IPMI_CC_OK; |
| 359 | } |
| 360 | |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 361 | ipmi_ret_t clearSEL(ipmi_netfn_t netfn, ipmi_cmd_t cmd, ipmi_request_t request, |
| 362 | ipmi_response_t response, ipmi_data_len_t data_len, |
| 363 | ipmi_context_t context) |
| 364 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 365 | auto requestData = |
| 366 | reinterpret_cast<const ipmi::sel::ClearSELRequest*>(request); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 367 | |
| 368 | if (g_sel_reserve != requestData->reservationID) |
| 369 | { |
| 370 | *data_len = 0; |
| 371 | return IPMI_CC_INVALID_RESERVATION_ID; |
| 372 | } |
| 373 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 374 | if (requestData->charC != 'C' || requestData->charL != 'L' || |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 375 | requestData->charR != 'R') |
| 376 | { |
| 377 | *data_len = 0; |
| 378 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 379 | } |
| 380 | |
| 381 | uint8_t eraseProgress = ipmi::sel::eraseComplete; |
| 382 | |
| 383 | /* |
| 384 | * Erasure status cannot be fetched from DBUS, so always return erasure |
| 385 | * status as `erase completed`. |
| 386 | */ |
| 387 | if (requestData->eraseOperation == ipmi::sel::getEraseStatus) |
| 388 | { |
| 389 | memcpy(response, &eraseProgress, sizeof(eraseProgress)); |
| 390 | *data_len = sizeof(eraseProgress); |
| 391 | return IPMI_CC_OK; |
| 392 | } |
| 393 | |
| 394 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 395 | ipmi::sel::ObjectPaths objectPaths; |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 396 | auto depth = 0; |
| 397 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 398 | auto mapperCall = |
| 399 | bus.new_method_call(ipmi::sel::mapperBusName, ipmi::sel::mapperObjPath, |
| 400 | ipmi::sel::mapperIntf, "GetSubTreePaths"); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 401 | mapperCall.append(ipmi::sel::logBasePath); |
| 402 | mapperCall.append(depth); |
| 403 | mapperCall.append(ipmi::sel::ObjectPaths({ipmi::sel::logEntryIntf})); |
| 404 | |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 405 | try |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 406 | { |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 407 | auto reply = bus.call(mapperCall); |
| 408 | if (reply.is_method_error()) |
| 409 | { |
| 410 | memcpy(response, &eraseProgress, sizeof(eraseProgress)); |
| 411 | *data_len = sizeof(eraseProgress); |
| 412 | return IPMI_CC_OK; |
| 413 | } |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 414 | |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 415 | reply.read(objectPaths); |
| 416 | if (objectPaths.empty()) |
| 417 | { |
| 418 | memcpy(response, &eraseProgress, sizeof(eraseProgress)); |
| 419 | *data_len = sizeof(eraseProgress); |
| 420 | return IPMI_CC_OK; |
| 421 | } |
| 422 | } |
| 423 | catch (const sdbusplus::exception::SdBusError& e) |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 424 | { |
| 425 | memcpy(response, &eraseProgress, sizeof(eraseProgress)); |
| 426 | *data_len = sizeof(eraseProgress); |
| 427 | return IPMI_CC_OK; |
| 428 | } |
| 429 | |
| 430 | std::string service; |
| 431 | |
| 432 | try |
| 433 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 434 | service = ipmi::getService(bus, ipmi::sel::logDeleteIntf, |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 435 | objectPaths.front()); |
| 436 | } |
| 437 | catch (const std::runtime_error& e) |
| 438 | { |
| 439 | log<level::ERR>(e.what()); |
| 440 | *data_len = 0; |
| 441 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 442 | } |
| 443 | |
| 444 | for (const auto& iter : objectPaths) |
| 445 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 446 | auto methodCall = bus.new_method_call( |
| 447 | service.c_str(), iter.c_str(), ipmi::sel::logDeleteIntf, "Delete"); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 448 | |
| 449 | auto reply = bus.call(methodCall); |
| 450 | if (reply.is_method_error()) |
| 451 | { |
| 452 | *data_len = 0; |
| 453 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | // Invalidate the cache of dbus entry objects. |
| 458 | cache::paths.clear(); |
| 459 | memcpy(response, &eraseProgress, sizeof(eraseProgress)); |
| 460 | *data_len = sizeof(eraseProgress); |
| 461 | return IPMI_CC_OK; |
| 462 | } |
| 463 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 464 | 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] | 465 | ipmi_request_t request, |
| 466 | ipmi_response_t response, |
| 467 | ipmi_data_len_t data_len, |
| 468 | ipmi_context_t context) |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 469 | { |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 470 | using namespace std::chrono; |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 471 | uint64_t host_time_usec = 0; |
| 472 | uint32_t resp = 0; |
Nagaraju Goruganti | 8960b7c | 2018-04-29 22:38:40 -0500 | [diff] [blame] | 473 | std::stringstream hostTime; |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 474 | |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 475 | try |
| 476 | { |
| 477 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 478 | auto service = ipmi::getService(bus, TIME_INTERFACE, HOST_TIME_PATH); |
| 479 | sdbusplus::message::variant<uint64_t> value; |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 480 | |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 481 | // Get host time |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 482 | auto method = bus.new_method_call(service.c_str(), HOST_TIME_PATH, |
| 483 | DBUS_PROPERTIES, "Get"); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 484 | |
| 485 | method.append(TIME_INTERFACE, PROPERTY_ELAPSED); |
| 486 | auto reply = bus.call(method); |
| 487 | if (reply.is_method_error()) |
| 488 | { |
| 489 | log<level::ERR>("Error getting time", |
| 490 | entry("SERVICE=%s", service.c_str()), |
| 491 | entry("PATH=%s", HOST_TIME_PATH)); |
| 492 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 493 | } |
| 494 | reply.read(value); |
| 495 | host_time_usec = value.get<uint64_t>(); |
| 496 | } |
| 497 | catch (InternalFailure& e) |
| 498 | { |
| 499 | log<level::ERR>(e.what()); |
| 500 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 501 | } |
| 502 | catch (const std::runtime_error& e) |
| 503 | { |
| 504 | log<level::ERR>(e.what()); |
| 505 | return IPMI_CC_UNSPECIFIED_ERROR; |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 506 | } |
| 507 | |
Nagaraju Goruganti | 8960b7c | 2018-04-29 22:38:40 -0500 | [diff] [blame] | 508 | hostTime << "Host time:" << getTimeString(host_time_usec); |
| 509 | log<level::DEBUG>(hostTime.str().c_str()); |
| 510 | |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 511 | // Time is really long int but IPMI wants just uint32. This works okay until |
| 512 | // the number of seconds since 1970 overflows uint32 size.. Still a whole |
| 513 | // lot of time here to even think about that. |
| 514 | resp = duration_cast<seconds>(microseconds(host_time_usec)).count(); |
| 515 | resp = htole32(resp); |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 516 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 517 | // From the IPMI Spec 2.0, response should be a 32-bit value |
| 518 | *data_len = sizeof(resp); |
| 519 | |
| 520 | // Pack the actual response |
| 521 | memcpy(response, &resp, *data_len); |
| 522 | |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 523 | return IPMI_CC_OK; |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | 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] | 527 | ipmi_request_t request, |
| 528 | ipmi_response_t response, |
| 529 | ipmi_data_len_t data_len, |
| 530 | ipmi_context_t context) |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 531 | { |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 532 | using namespace std::chrono; |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 533 | ipmi_ret_t rc = IPMI_CC_OK; |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 534 | uint32_t secs = *static_cast<uint32_t*>(request); |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 535 | *data_len = 0; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 536 | |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 537 | secs = le32toh(secs); |
| 538 | microseconds usec{seconds(secs)}; |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 539 | |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 540 | try |
| 541 | { |
| 542 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 543 | auto service = ipmi::getService(bus, TIME_INTERFACE, HOST_TIME_PATH); |
| 544 | sdbusplus::message::variant<uint64_t> value{usec.count()}; |
| 545 | |
| 546 | // Set host time |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 547 | auto method = bus.new_method_call(service.c_str(), HOST_TIME_PATH, |
| 548 | DBUS_PROPERTIES, "Set"); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 549 | |
| 550 | method.append(TIME_INTERFACE, PROPERTY_ELAPSED, value); |
| 551 | auto reply = bus.call(method); |
| 552 | if (reply.is_method_error()) |
| 553 | { |
| 554 | log<level::ERR>("Error setting time", |
| 555 | entry("SERVICE=%s", service.c_str()), |
| 556 | entry("PATH=%s", HOST_TIME_PATH)); |
| 557 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 558 | } |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 559 | } |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 560 | catch (InternalFailure& e) |
| 561 | { |
| 562 | log<level::ERR>(e.what()); |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 563 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 564 | } |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 565 | catch (const std::runtime_error& e) |
| 566 | { |
| 567 | log<level::ERR>(e.what()); |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 568 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 569 | } |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 570 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 571 | return rc; |
| 572 | } |
| 573 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 574 | 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] | 575 | ipmi_request_t request, |
| 576 | ipmi_response_t response, |
| 577 | ipmi_data_len_t data_len, |
| 578 | ipmi_context_t context) |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 579 | { |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 580 | ipmi_ret_t rc = IPMI_CC_OK; |
| 581 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 582 | // IPMI spec, Reservation ID, the value simply increases against each |
| 583 | // execution of reserve_sel command. |
| 584 | if (++g_sel_reserve == 0) |
Nan Li | 36c0cb6 | 2016-03-31 11:16:08 +0800 | [diff] [blame] | 585 | g_sel_reserve = 1; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 586 | |
| 587 | *data_len = sizeof(g_sel_reserve); |
| 588 | |
| 589 | // Pack the actual response |
| 590 | memcpy(response, &g_sel_reserve, *data_len); |
| 591 | |
| 592 | return rc; |
| 593 | } |
| 594 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 595 | 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] | 596 | ipmi_request_t request, |
| 597 | ipmi_response_t response, |
| 598 | ipmi_data_len_t data_len, |
| 599 | ipmi_context_t context) |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 600 | { |
| 601 | |
| 602 | ipmi_ret_t rc = IPMI_CC_OK; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 603 | ipmi_add_sel_request_t* p = (ipmi_add_sel_request_t*)request; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 604 | uint16_t recordid; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 605 | |
Chris Austen | 313d95b | 2015-10-31 12:55:30 -0500 | [diff] [blame] | 606 | recordid = ((uint16_t)p->eventdata[1] << 8) | p->eventdata[2]; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 607 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 608 | *data_len = sizeof(g_sel_reserve); |
| 609 | |
| 610 | // Pack the actual response |
Chris Austen | 7cc3332 | 2015-11-11 00:20:22 -0600 | [diff] [blame] | 611 | memcpy(response, &p->eventdata[1], 2); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 612 | |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 613 | // Hostboot sends SEL with OEM record type 0xDE to indicate that there is |
| 614 | // a maintenance procedure associated with eSEL record. |
| 615 | static constexpr auto procedureType = 0xDE; |
| 616 | if (p->recordtype == procedureType) |
| 617 | { |
| 618 | // In the OEM record type 0xDE, byte 11 in the SEL record indicate the |
| 619 | // procedure number. |
| 620 | createProcedureLogEntry(p->sensortype); |
| 621 | } |
| 622 | else |
| 623 | { |
| 624 | send_esel(recordid); |
| 625 | } |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 626 | |
| 627 | return rc; |
| 628 | } |
| 629 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 630 | // Read FRU info area |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 631 | ipmi_ret_t ipmi_storage_get_fru_inv_area_info( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 632 | ipmi_netfn_t netfn, ipmi_cmd_t cmd, ipmi_request_t request, |
| 633 | 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] | 634 | { |
| 635 | ipmi_ret_t rc = IPMI_CC_OK; |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 636 | const FruInvenAreaInfoRequest* reqptr = |
| 637 | reinterpret_cast<const FruInvenAreaInfoRequest*>(request); |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 638 | |
| 639 | auto iter = frus.find(reqptr->fruID); |
| 640 | if (iter == frus.end()) |
| 641 | { |
| 642 | *data_len = 0; |
| 643 | return IPMI_CC_SENSOR_INVALID; |
| 644 | } |
| 645 | |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 646 | try |
| 647 | { |
| 648 | const auto& fruArea = getFruAreaData(reqptr->fruID); |
| 649 | auto size = static_cast<uint16_t>(fruArea.size()); |
| 650 | FruInvenAreaInfoResponse resp; |
| 651 | resp.sizems = size >> 8; |
| 652 | resp.sizels = size; |
| 653 | resp.access = static_cast<uint8_t>(AccessMode::bytes); |
| 654 | |
| 655 | *data_len = sizeof(resp); |
| 656 | |
| 657 | // Pack the actual response |
| 658 | memcpy(response, &resp, *data_len); |
| 659 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 660 | catch (const InternalFailure& e) |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 661 | { |
| 662 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 663 | *data_len = 0; |
| 664 | log<level::ERR>(e.what()); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 665 | } |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 666 | return rc; |
| 667 | } |
| 668 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 669 | // Read FRU data |
| 670 | ipmi_ret_t ipmi_storage_read_fru_data(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 671 | ipmi_request_t request, |
| 672 | ipmi_response_t response, |
| 673 | ipmi_data_len_t data_len, |
| 674 | ipmi_context_t context) |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 675 | { |
| 676 | ipmi_ret_t rc = IPMI_CC_OK; |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 677 | const ReadFruDataRequest* reqptr = |
Nagaraju Goruganti | 7f2d7c9 | 2018-03-21 11:18:30 -0500 | [diff] [blame] | 678 | reinterpret_cast<const ReadFruDataRequest*>(request); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 679 | auto resptr = reinterpret_cast<ReadFruDataResponse*>(response); |
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 | auto offset = |
| 689 | static_cast<uint16_t>(reqptr->offsetMS << 8 | reqptr->offsetLS); |
| 690 | try |
| 691 | { |
| 692 | const auto& fruArea = getFruAreaData(reqptr->fruID); |
| 693 | auto size = fruArea.size(); |
Nagaraju Goruganti | 7f2d7c9 | 2018-03-21 11:18:30 -0500 | [diff] [blame] | 694 | |
Tom Joseph | efcd68b | 2018-04-26 18:46:27 +0530 | [diff] [blame] | 695 | if (offset >= size) |
| 696 | { |
| 697 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 698 | } |
| 699 | |
Nagaraju Goruganti | 7f2d7c9 | 2018-03-21 11:18:30 -0500 | [diff] [blame] | 700 | // Write the count of response data. |
| 701 | if ((offset + reqptr->count) <= size) |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 702 | { |
Nagaraju Goruganti | 7f2d7c9 | 2018-03-21 11:18:30 -0500 | [diff] [blame] | 703 | resptr->count = reqptr->count; |
| 704 | } |
| 705 | else |
| 706 | { |
| 707 | resptr->count = size - offset; |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 708 | } |
Ratan Gupta | 2848d60 | 2018-01-31 20:39:20 +0530 | [diff] [blame] | 709 | |
Ratan Gupta | 2848d60 | 2018-01-31 20:39:20 +0530 | [diff] [blame] | 710 | std::copy((fruArea.begin() + offset), |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 711 | (fruArea.begin() + offset + resptr->count), resptr->data); |
Ratan Gupta | 2848d60 | 2018-01-31 20:39:20 +0530 | [diff] [blame] | 712 | |
Nagaraju Goruganti | 7f2d7c9 | 2018-03-21 11:18:30 -0500 | [diff] [blame] | 713 | *data_len = resptr->count + 1; // additional one byte for count |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 714 | } |
| 715 | catch (const InternalFailure& e) |
| 716 | { |
| 717 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 718 | *data_len = 0; |
| 719 | log<level::ERR>(e.what()); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 720 | } |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 721 | return rc; |
| 722 | } |
| 723 | |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 724 | 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] | 725 | ipmi_request_t request, |
| 726 | ipmi_response_t response, |
| 727 | ipmi_data_len_t data_len, |
| 728 | ipmi_context_t context) |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 729 | { |
| 730 | constexpr auto sdrVersion = 0x51; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 731 | auto responseData = reinterpret_cast<GetRepositoryInfoResponse*>(response); |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 732 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 733 | memset(responseData, 0, sizeof(GetRepositoryInfoResponse)); |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 734 | |
| 735 | responseData->sdrVersion = sdrVersion; |
| 736 | |
| 737 | uint16_t records = frus.size() + sensors.size(); |
| 738 | responseData->recordCountMs = records >> 8; |
| 739 | responseData->recordCountLs = records; |
| 740 | |
| 741 | responseData->freeSpace[0] = 0xFF; |
| 742 | responseData->freeSpace[1] = 0xFF; |
| 743 | |
| 744 | *data_len = sizeof(GetRepositoryInfoResponse); |
| 745 | |
| 746 | return IPMI_CC_OK; |
| 747 | } |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 748 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 749 | void register_netfn_storage_functions() |
| 750 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 751 | // <Wildcard Command> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 752 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_WILDCARD, NULL, |
| 753 | ipmi_storage_wildcard, PRIVILEGE_USER); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 754 | |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 755 | // <Get SEL Info> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 756 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_INFO, NULL, |
| 757 | getSELInfo, PRIVILEGE_USER); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 758 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 759 | // <Get SEL Time> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 760 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_TIME, NULL, |
| 761 | ipmi_storage_get_sel_time, PRIVILEGE_USER); |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 762 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 763 | // <Set SEL Time> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 764 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_SET_SEL_TIME, NULL, |
| 765 | ipmi_storage_set_sel_time, PRIVILEGE_OPERATOR); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 766 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 767 | // <Reserve SEL> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 768 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_RESERVE_SEL, NULL, |
| 769 | ipmi_storage_reserve_sel, PRIVILEGE_USER); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 770 | |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 771 | // <Get SEL Entry> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 772 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY, NULL, |
| 773 | getSELEntry, PRIVILEGE_USER); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 774 | |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 775 | // <Delete SEL Entry> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 776 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_DELETE_SEL, NULL, |
| 777 | deleteSELEntry, PRIVILEGE_OPERATOR); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 778 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 779 | // <Add SEL Entry> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 780 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_ADD_SEL, NULL, |
| 781 | ipmi_storage_add_sel, PRIVILEGE_OPERATOR); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 782 | // <Clear SEL> |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 783 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_CLEAR_SEL, NULL, clearSEL, |
| 784 | PRIVILEGE_OPERATOR); |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 785 | // <Get FRU Inventory Area Info> |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 786 | 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] | 787 | ipmi_storage_get_fru_inv_area_info, |
| 788 | PRIVILEGE_OPERATOR); |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 789 | |
| 790 | // <Add READ FRU Data |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 791 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_READ_FRU_DATA, NULL, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 792 | ipmi_storage_read_fru_data, PRIVILEGE_OPERATOR); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 793 | |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 794 | // <Get Repository Info> |
| 795 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_REPOSITORY_INFO, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 796 | nullptr, ipmi_get_repository_info, PRIVILEGE_USER); |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 797 | |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 798 | // <Reserve SDR Repository> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 799 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_RESERVE_SDR, nullptr, |
| 800 | ipmi_sen_reserve_sdr, PRIVILEGE_USER); |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 801 | |
| 802 | // <Get SDR> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 803 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SDR, nullptr, |
| 804 | ipmi_sen_get_sdr, PRIVILEGE_USER); |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 805 | |
Marri Devender Rao | 908f750 | 2017-07-10 01:49:54 -0500 | [diff] [blame] | 806 | ipmi::fru::registerCallbackHandler(); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 807 | return; |
| 808 | } |