Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 1 | #include <cstdio> |
| 2 | #include <string> |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 3 | #include <arpa/inet.h> |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 4 | #include <systemd/sd-bus.h> |
| 5 | #include <mapper.h> |
| 6 | #include <chrono> |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 7 | #include "selutility.hpp" |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 8 | #include "storagehandler.h" |
| 9 | #include "storageaddsel.h" |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame^] | 10 | #include "utils.hpp" |
Patrick Williams | 37af733 | 2016-09-02 21:21:42 -0500 | [diff] [blame] | 11 | #include "host-ipmid/ipmid-api.h" |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 12 | #include <experimental/filesystem> |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 13 | #include <phosphor-logging/log.hpp> |
| 14 | #include <sdbusplus/server.hpp> |
| 15 | #include "xyz/openbmc_project/Common/error.hpp" |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 16 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 17 | void register_netfn_storage_functions() __attribute__((constructor)); |
| 18 | |
| 19 | |
| 20 | unsigned int g_sel_time = 0xFFFFFFFF; |
Nan Li | 36c0cb6 | 2016-03-31 11:16:08 +0800 | [diff] [blame] | 21 | extern unsigned short g_sel_reserve; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 22 | |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 23 | constexpr auto time_manager_intf = "org.openbmc.TimeManager"; |
| 24 | constexpr auto time_manager_obj = "/org/openbmc/TimeManager"; |
| 25 | |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 26 | namespace cache |
| 27 | { |
| 28 | /* |
| 29 | * This cache contains the object paths of the logging entries sorted in the |
| 30 | * order of the filename(numeric order). The cache is initialized by |
| 31 | * invoking readLoggingObjectPaths with the cache as the parameter. The |
| 32 | * cache is invoked in the execution of the Get SEL info and Delete SEL |
| 33 | * entry command. The Get SEL Info command is typically invoked before the |
| 34 | * Get SEL entry command, so the cache is utilized for responding to Get SEL |
| 35 | * entry command. The cache is invalidated by clearing after Delete SEL |
| 36 | * entry and Clear SEL command. |
| 37 | */ |
| 38 | ipmi::sel::ObjectPaths paths; |
| 39 | |
| 40 | } // namespace objectPathsCache |
| 41 | |
| 42 | using InternalFailure = |
| 43 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
| 44 | using namespace phosphor::logging; |
| 45 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 46 | ipmi_ret_t ipmi_storage_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 47 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 48 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 49 | { |
| 50 | printf("Handling STORAGE WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 51 | // Status code. |
Nan Li | 70aa8d9 | 2016-08-29 00:11:10 +0800 | [diff] [blame] | 52 | ipmi_ret_t rc = IPMI_CC_INVALID; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 53 | *data_len = 0; |
| 54 | return rc; |
| 55 | } |
| 56 | |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 57 | ipmi_ret_t getSELInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 58 | ipmi_request_t request, ipmi_response_t response, |
| 59 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 60 | { |
| 61 | std::vector<uint8_t> outPayload(sizeof(ipmi::sel::GetSELInfoResponse)); |
| 62 | auto responseData = reinterpret_cast<ipmi::sel::GetSELInfoResponse*> |
| 63 | (outPayload.data()); |
| 64 | |
| 65 | responseData->selVersion = ipmi::sel::selVersion; |
| 66 | // Last erase timestamp is not available from log manager. |
| 67 | responseData->eraseTimeStamp = ipmi::sel::invalidTimeStamp; |
| 68 | responseData->operationSupport = ipmi::sel::operationSupport; |
| 69 | |
| 70 | ipmi::sel::readLoggingObjectPaths(cache::paths); |
| 71 | responseData->entries = 0; |
| 72 | responseData->addTimeStamp = ipmi::sel::invalidTimeStamp; |
| 73 | |
| 74 | if (!cache::paths.empty()) |
| 75 | { |
| 76 | responseData->entries = static_cast<uint16_t>(cache::paths.size()); |
| 77 | |
| 78 | try |
| 79 | { |
| 80 | responseData->addTimeStamp = static_cast<uint32_t>( |
| 81 | (ipmi::sel::getEntryTimeStamp(cache::paths.back()) |
| 82 | .count())); |
| 83 | } |
| 84 | catch (InternalFailure& e) |
| 85 | { |
| 86 | } |
| 87 | catch (const std::runtime_error& e) |
| 88 | { |
| 89 | log<level::ERR>(e.what()); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | memcpy(response, outPayload.data(), outPayload.size()); |
| 94 | *data_len = outPayload.size(); |
| 95 | |
| 96 | return IPMI_CC_OK; |
| 97 | } |
| 98 | |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 99 | ipmi_ret_t getSELEntry(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 100 | ipmi_request_t request, ipmi_response_t response, |
| 101 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 102 | { |
| 103 | auto requestData = reinterpret_cast<const ipmi::sel::GetSELEntryRequest*> |
| 104 | (request); |
| 105 | |
| 106 | if (requestData->reservationID != 0) |
| 107 | { |
| 108 | if (g_sel_reserve != requestData->reservationID) |
| 109 | { |
| 110 | *data_len = 0; |
| 111 | return IPMI_CC_INVALID_RESERVATION_ID; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | if (cache::paths.empty()) |
| 116 | { |
| 117 | *data_len = 0; |
| 118 | return IPMI_CC_SENSOR_INVALID; |
| 119 | } |
| 120 | |
| 121 | ipmi::sel::ObjectPaths::const_iterator iter; |
| 122 | |
| 123 | // Check for the requested SEL Entry. |
| 124 | if (requestData->selRecordID == ipmi::sel::firstEntry) |
| 125 | { |
| 126 | iter = cache::paths.begin(); |
| 127 | } |
| 128 | else if (requestData->selRecordID == ipmi::sel::lastEntry) |
| 129 | { |
| 130 | iter = cache::paths.end(); |
| 131 | } |
| 132 | else |
| 133 | { |
| 134 | std::string objPath = std::string(ipmi::sel::logBasePath) + "/" + |
| 135 | std::to_string(requestData->selRecordID); |
| 136 | |
| 137 | iter = std::find(cache::paths.begin(), cache::paths.end(), objPath); |
| 138 | if (iter == cache::paths.end()) |
| 139 | { |
| 140 | *data_len = 0; |
| 141 | return IPMI_CC_SENSOR_INVALID; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | ipmi::sel::GetSELEntryResponse record {}; |
| 146 | |
| 147 | // Convert the log entry into SEL record. |
| 148 | try |
| 149 | { |
| 150 | record = ipmi::sel::convertLogEntrytoSEL(*iter); |
| 151 | } |
| 152 | catch (InternalFailure& e) |
| 153 | { |
| 154 | *data_len = 0; |
| 155 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 156 | } |
| 157 | catch (const std::runtime_error& e) |
| 158 | { |
| 159 | log<level::ERR>(e.what()); |
| 160 | *data_len = 0; |
| 161 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 162 | } |
| 163 | |
| 164 | |
| 165 | // Identify the next SEL record ID |
| 166 | if(iter != cache::paths.end()) |
| 167 | { |
| 168 | ++iter; |
| 169 | if (iter == cache::paths.end()) |
| 170 | { |
| 171 | record.nextRecordID = ipmi::sel::lastEntry; |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | namespace fs = std::experimental::filesystem; |
| 176 | fs::path path(*iter); |
| 177 | record.nextRecordID = static_cast<uint16_t> |
| 178 | (std::stoul(std::string(path.filename().c_str()))); |
| 179 | } |
| 180 | } |
| 181 | else |
| 182 | { |
| 183 | record.nextRecordID = ipmi::sel::lastEntry; |
| 184 | } |
| 185 | |
| 186 | if (requestData->readLength == ipmi::sel::entireRecord) |
| 187 | { |
| 188 | memcpy(response, &record, sizeof(record)); |
| 189 | *data_len = sizeof(record); |
| 190 | } |
| 191 | else |
| 192 | { |
| 193 | if (requestData->offset >= ipmi::sel::selRecordSize || |
| 194 | requestData->readLength > ipmi::sel::selRecordSize) |
| 195 | { |
| 196 | *data_len = 0; |
| 197 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 198 | } |
| 199 | |
| 200 | auto diff = ipmi::sel::selRecordSize - requestData->offset; |
| 201 | auto readLength = std::min(diff, |
| 202 | static_cast<int>(requestData->readLength)); |
| 203 | |
| 204 | memcpy(response, &record.nextRecordID, sizeof(record.nextRecordID)); |
| 205 | memcpy(static_cast<uint8_t*>(response) + sizeof(record.nextRecordID), |
| 206 | &record.recordID + requestData->offset, readLength); |
| 207 | *data_len = sizeof(record.nextRecordID) + readLength; |
| 208 | } |
| 209 | |
| 210 | return IPMI_CC_OK; |
| 211 | } |
| 212 | |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame^] | 213 | ipmi_ret_t deleteSELEntry(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 214 | ipmi_request_t request, ipmi_response_t response, |
| 215 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 216 | { |
| 217 | namespace fs = std::experimental::filesystem; |
| 218 | auto requestData = reinterpret_cast<const ipmi::sel::DeleteSELEntryRequest*> |
| 219 | (request); |
| 220 | |
| 221 | if (g_sel_reserve != requestData->reservationID) |
| 222 | { |
| 223 | *data_len = 0; |
| 224 | return IPMI_CC_INVALID_RESERVATION_ID; |
| 225 | } |
| 226 | |
| 227 | ipmi::sel::readLoggingObjectPaths(cache::paths); |
| 228 | |
| 229 | if (cache::paths.empty()) |
| 230 | { |
| 231 | *data_len = 0; |
| 232 | return IPMI_CC_SENSOR_INVALID; |
| 233 | } |
| 234 | |
| 235 | ipmi::sel::ObjectPaths::const_iterator iter; |
| 236 | uint16_t delRecordID = 0; |
| 237 | |
| 238 | if (requestData->selRecordID == ipmi::sel::firstEntry) |
| 239 | { |
| 240 | iter = cache::paths.begin(); |
| 241 | fs::path path(*iter); |
| 242 | delRecordID = static_cast<uint16_t> |
| 243 | (std::stoul(std::string(path.filename().c_str()))); |
| 244 | } |
| 245 | else if (requestData->selRecordID == ipmi::sel::lastEntry) |
| 246 | { |
| 247 | iter = cache::paths.end(); |
| 248 | fs::path path(*iter); |
| 249 | delRecordID = static_cast<uint16_t> |
| 250 | (std::stoul(std::string(path.filename().c_str()))); |
| 251 | } |
| 252 | else |
| 253 | { |
| 254 | std::string objPath = std::string(ipmi::sel::logBasePath) + "/" + |
| 255 | std::to_string(requestData->selRecordID); |
| 256 | |
| 257 | iter = std::find(cache::paths.begin(), cache::paths.end(), objPath); |
| 258 | if (iter == cache::paths.end()) |
| 259 | { |
| 260 | *data_len = 0; |
| 261 | return IPMI_CC_SENSOR_INVALID; |
| 262 | } |
| 263 | delRecordID = requestData->selRecordID; |
| 264 | } |
| 265 | |
| 266 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 267 | std::string service; |
| 268 | |
| 269 | try |
| 270 | { |
| 271 | service = ipmi::getService(bus, ipmi::sel::logDeleteIntf, *iter); |
| 272 | } |
| 273 | catch (const std::runtime_error& e) |
| 274 | { |
| 275 | log<level::ERR>(e.what()); |
| 276 | *data_len = 0; |
| 277 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 278 | } |
| 279 | |
| 280 | auto methodCall = bus.new_method_call(service.c_str(), |
| 281 | (*iter).c_str(), |
| 282 | ipmi::sel::logDeleteIntf, |
| 283 | "Delete"); |
| 284 | auto reply = bus.call(methodCall); |
| 285 | if (reply.is_method_error()) |
| 286 | { |
| 287 | *data_len = 0; |
| 288 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 289 | } |
| 290 | |
| 291 | // Invalidate the cache of dbus entry objects. |
| 292 | cache::paths.clear(); |
| 293 | memcpy(response, &delRecordID, sizeof(delRecordID)); |
| 294 | *data_len = sizeof(delRecordID); |
| 295 | |
| 296 | return IPMI_CC_OK; |
| 297 | } |
| 298 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 299 | ipmi_ret_t ipmi_storage_get_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 300 | ipmi_request_t request, ipmi_response_t response, |
| 301 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 302 | { |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 303 | using namespace std::chrono; |
| 304 | |
| 305 | char *time_provider = nullptr; |
| 306 | const char* time_in_str = nullptr; |
| 307 | uint64_t host_time_usec = 0; |
| 308 | uint32_t resp = 0; |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 309 | ipmi_ret_t rc = IPMI_CC_OK; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 310 | |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 311 | sd_bus_message *reply = nullptr; |
| 312 | sd_bus_error bus_error = SD_BUS_ERROR_NULL; |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 313 | |
| 314 | printf("IPMI Handling GET-SEL-TIME\n"); |
| 315 | |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 316 | auto bus = ipmid_get_sd_bus_connection(); |
| 317 | |
| 318 | auto rct = mapper_get_service(bus, time_manager_obj, &time_provider); |
| 319 | if (rct < 0) { |
| 320 | printf("Error [%s] getting bus name for time provider\n", |
| 321 | strerror(-rct)); |
| 322 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 323 | goto finish; |
| 324 | } |
| 325 | |
| 326 | rct = sd_bus_call_method(bus, |
| 327 | time_provider, |
| 328 | time_manager_obj, |
| 329 | time_manager_intf, |
| 330 | "GetTime", |
| 331 | &bus_error, |
| 332 | &reply, |
| 333 | "s", |
| 334 | "host"); |
| 335 | if (rct < 0) { |
| 336 | printf("Error [%s] getting time\n", strerror(-rct)); |
| 337 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 338 | goto finish; |
| 339 | } |
| 340 | |
| 341 | rct = sd_bus_message_read(reply, "sx", &time_in_str, &host_time_usec); |
| 342 | if (rct < 0) { |
| 343 | fprintf(stderr, "Error [%s] parsing get-time response\n", |
| 344 | strerror(-rct)); |
| 345 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 346 | goto finish; |
| 347 | } |
| 348 | |
| 349 | // Time is really long int but IPMI wants just uint32. This works okay until |
| 350 | // the number of seconds since 1970 overflows uint32 size.. Still a whole |
| 351 | // lot of time here to even think about that. |
| 352 | resp = duration_cast<seconds>(microseconds(host_time_usec)).count(); |
| 353 | resp = htole32(resp); |
| 354 | printf("Host Time read:[%s] :: [%d]\n", time_in_str, resp); |
| 355 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 356 | // From the IPMI Spec 2.0, response should be a 32-bit value |
| 357 | *data_len = sizeof(resp); |
| 358 | |
| 359 | // Pack the actual response |
| 360 | memcpy(response, &resp, *data_len); |
| 361 | |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 362 | finish: |
| 363 | sd_bus_error_free(&bus_error); |
| 364 | reply = sd_bus_message_unref(reply); |
| 365 | free(time_provider); |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 366 | return rc; |
| 367 | } |
| 368 | |
| 369 | ipmi_ret_t ipmi_storage_set_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 370 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 371 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 372 | { |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 373 | char *time_provider = nullptr; |
| 374 | int time_rc = 0; |
| 375 | ipmi_ret_t rc = IPMI_CC_OK; |
| 376 | |
| 377 | sd_bus_message *reply = nullptr; |
| 378 | sd_bus_error bus_error = SD_BUS_ERROR_NULL; |
| 379 | |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 380 | uint32_t* secs = (uint32_t*)request; |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 381 | *data_len = 0; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 382 | |
| 383 | printf("Handling Set-SEL-Time:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 384 | printf("Data: 0x%X]\n",*secs); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 385 | |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 386 | auto bus = ipmid_get_sd_bus_connection(); |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 387 | |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 388 | auto rct = mapper_get_service(bus, time_manager_obj, &time_provider); |
| 389 | if (rct < 0) { |
| 390 | printf("Error [%s] getting bus name for time provider\n", |
| 391 | strerror(-rct)); |
| 392 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 393 | goto finish; |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 394 | } |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 395 | |
| 396 | rct = sd_bus_call_method(bus, |
| 397 | time_provider, |
| 398 | time_manager_obj, |
| 399 | time_manager_intf, |
| 400 | "SetTime", |
| 401 | &bus_error, |
| 402 | &reply, |
| 403 | "ss", |
| 404 | "host", |
| 405 | std::to_string(le32toh(*secs)).c_str()); |
| 406 | |
| 407 | if (rct < 0) { |
| 408 | printf("Error [%s] setting time\n", strerror(-rct)); |
| 409 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 410 | goto finish; |
| 411 | } |
| 412 | |
| 413 | rct = sd_bus_message_read(reply, "i", &time_rc); |
| 414 | if (rct < 0) { |
| 415 | fprintf(stderr, "Error [%s] parsing set-time response\n", |
| 416 | strerror(-rct)); |
| 417 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 418 | goto finish; |
| 419 | } |
| 420 | |
| 421 | if (time_rc < 0) { |
| 422 | printf("Error setting time."); |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 423 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 424 | } |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 425 | |
| 426 | finish: |
| 427 | sd_bus_error_free(&bus_error); |
| 428 | reply = sd_bus_message_unref(reply); |
| 429 | free(time_provider); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 430 | return rc; |
| 431 | } |
| 432 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 433 | ipmi_ret_t ipmi_storage_reserve_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 434 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 435 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 436 | { |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 437 | ipmi_ret_t rc = IPMI_CC_OK; |
| 438 | |
Nan Li | 36c0cb6 | 2016-03-31 11:16:08 +0800 | [diff] [blame] | 439 | // IPMI spec, Reservation ID, the value simply increases against each execution of reserve_sel command. |
| 440 | if( ++g_sel_reserve == 0) |
| 441 | g_sel_reserve = 1; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 442 | |
Nan Li | 36c0cb6 | 2016-03-31 11:16:08 +0800 | [diff] [blame] | 443 | printf("IPMI Handling RESERVE-SEL 0x%04x\n", g_sel_reserve); |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 444 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 445 | *data_len = sizeof(g_sel_reserve); |
| 446 | |
| 447 | // Pack the actual response |
| 448 | memcpy(response, &g_sel_reserve, *data_len); |
| 449 | |
| 450 | return rc; |
| 451 | } |
| 452 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 453 | ipmi_ret_t ipmi_storage_add_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 454 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 455 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 456 | { |
| 457 | |
| 458 | ipmi_ret_t rc = IPMI_CC_OK; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 459 | ipmi_add_sel_request_t *p = (ipmi_add_sel_request_t*) request; |
| 460 | uint16_t recordid; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 461 | |
Chris Austen | 313d95b | 2015-10-31 12:55:30 -0500 | [diff] [blame] | 462 | recordid = ((uint16_t)p->eventdata[1] << 8) | p->eventdata[2]; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 463 | |
| 464 | printf("IPMI Handling ADD-SEL for record 0x%04x\n", recordid); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 465 | |
| 466 | *data_len = sizeof(g_sel_reserve); |
| 467 | |
| 468 | // Pack the actual response |
Chris Austen | 7cc3332 | 2015-11-11 00:20:22 -0600 | [diff] [blame] | 469 | memcpy(response, &p->eventdata[1], 2); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 470 | |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 471 | send_esel(recordid); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 472 | |
| 473 | return rc; |
| 474 | } |
| 475 | |
| 476 | |
| 477 | |
| 478 | void register_netfn_storage_functions() |
| 479 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 480 | // <Wildcard Command> |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 481 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_WILDCARD); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 482 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_WILDCARD, NULL, ipmi_storage_wildcard, |
| 483 | PRIVILEGE_USER); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 484 | |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 485 | // <Get SEL Info> |
| 486 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_GET_SEL_INFO); |
| 487 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_INFO, NULL, getSELInfo, |
| 488 | PRIVILEGE_USER); |
| 489 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 490 | // <Get SEL Time> |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 491 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_GET_SEL_TIME); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 492 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_TIME, NULL, ipmi_storage_get_sel_time, |
| 493 | PRIVILEGE_USER); |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 494 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 495 | // <Set SEL Time> |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 496 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_SET_SEL_TIME); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 497 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_SET_SEL_TIME, NULL, ipmi_storage_set_sel_time, |
| 498 | PRIVILEGE_OPERATOR); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 499 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 500 | // <Reserve SEL> |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 501 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_RESERVE_SEL); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 502 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_RESERVE_SEL, NULL, ipmi_storage_reserve_sel, |
| 503 | PRIVILEGE_USER); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 504 | |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 505 | // <Get SEL Entry> |
| 506 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY); |
| 507 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY, NULL, getSELEntry, |
| 508 | PRIVILEGE_USER); |
| 509 | |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame^] | 510 | // <Delete SEL Entry> |
| 511 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_DELETE_SEL); |
| 512 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_DELETE_SEL, NULL, deleteSELEntry, |
| 513 | PRIVILEGE_OPERATOR); |
| 514 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 515 | // <Add SEL Entry> |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 516 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_ADD_SEL); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 517 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_ADD_SEL, NULL, ipmi_storage_add_sel, |
| 518 | PRIVILEGE_OPERATOR); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 519 | return; |
| 520 | } |
| 521 | |