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 | |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame^] | 299 | ipmi_ret_t clearSEL(ipmi_netfn_t netfn, ipmi_cmd_t cmd, ipmi_request_t request, |
| 300 | ipmi_response_t response, ipmi_data_len_t data_len, |
| 301 | ipmi_context_t context) |
| 302 | { |
| 303 | auto requestData = reinterpret_cast<const ipmi::sel::ClearSELRequest*> |
| 304 | (request); |
| 305 | |
| 306 | if (g_sel_reserve != requestData->reservationID) |
| 307 | { |
| 308 | *data_len = 0; |
| 309 | return IPMI_CC_INVALID_RESERVATION_ID; |
| 310 | } |
| 311 | |
| 312 | if (requestData->charC != 'C' || |
| 313 | requestData->charL != 'L' || |
| 314 | requestData->charR != 'R') |
| 315 | { |
| 316 | *data_len = 0; |
| 317 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 318 | } |
| 319 | |
| 320 | uint8_t eraseProgress = ipmi::sel::eraseComplete; |
| 321 | |
| 322 | /* |
| 323 | * Erasure status cannot be fetched from DBUS, so always return erasure |
| 324 | * status as `erase completed`. |
| 325 | */ |
| 326 | if (requestData->eraseOperation == ipmi::sel::getEraseStatus) |
| 327 | { |
| 328 | memcpy(response, &eraseProgress, sizeof(eraseProgress)); |
| 329 | *data_len = sizeof(eraseProgress); |
| 330 | return IPMI_CC_OK; |
| 331 | } |
| 332 | |
| 333 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 334 | auto depth = 0; |
| 335 | |
| 336 | auto mapperCall = bus.new_method_call(ipmi::sel::mapperBusName, |
| 337 | ipmi::sel::mapperObjPath, |
| 338 | ipmi::sel::mapperIntf, |
| 339 | "GetSubTreePaths"); |
| 340 | mapperCall.append(ipmi::sel::logBasePath); |
| 341 | mapperCall.append(depth); |
| 342 | mapperCall.append(ipmi::sel::ObjectPaths({ipmi::sel::logEntryIntf})); |
| 343 | |
| 344 | auto reply = bus.call(mapperCall); |
| 345 | if (reply.is_method_error()) |
| 346 | { |
| 347 | memcpy(response, &eraseProgress, sizeof(eraseProgress)); |
| 348 | *data_len = sizeof(eraseProgress); |
| 349 | return IPMI_CC_OK; |
| 350 | } |
| 351 | |
| 352 | ipmi::sel::ObjectPaths objectPaths; |
| 353 | reply.read(objectPaths); |
| 354 | if (objectPaths.empty()) |
| 355 | { |
| 356 | memcpy(response, &eraseProgress, sizeof(eraseProgress)); |
| 357 | *data_len = sizeof(eraseProgress); |
| 358 | return IPMI_CC_OK; |
| 359 | } |
| 360 | |
| 361 | std::string service; |
| 362 | |
| 363 | try |
| 364 | { |
| 365 | service = ipmi::getService(bus, |
| 366 | ipmi::sel::logDeleteIntf, |
| 367 | objectPaths.front()); |
| 368 | } |
| 369 | catch (const std::runtime_error& e) |
| 370 | { |
| 371 | log<level::ERR>(e.what()); |
| 372 | *data_len = 0; |
| 373 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 374 | } |
| 375 | |
| 376 | for (const auto& iter : objectPaths) |
| 377 | { |
| 378 | auto methodCall = bus.new_method_call(service.c_str(), |
| 379 | iter.c_str(), |
| 380 | ipmi::sel::logDeleteIntf, |
| 381 | "Delete"); |
| 382 | |
| 383 | auto reply = bus.call(methodCall); |
| 384 | if (reply.is_method_error()) |
| 385 | { |
| 386 | *data_len = 0; |
| 387 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | // Invalidate the cache of dbus entry objects. |
| 392 | cache::paths.clear(); |
| 393 | memcpy(response, &eraseProgress, sizeof(eraseProgress)); |
| 394 | *data_len = sizeof(eraseProgress); |
| 395 | return IPMI_CC_OK; |
| 396 | } |
| 397 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 398 | ipmi_ret_t ipmi_storage_get_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 399 | ipmi_request_t request, ipmi_response_t response, |
| 400 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 401 | { |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 402 | using namespace std::chrono; |
| 403 | |
| 404 | char *time_provider = nullptr; |
| 405 | const char* time_in_str = nullptr; |
| 406 | uint64_t host_time_usec = 0; |
| 407 | uint32_t resp = 0; |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 408 | ipmi_ret_t rc = IPMI_CC_OK; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 409 | |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 410 | sd_bus_message *reply = nullptr; |
| 411 | sd_bus_error bus_error = SD_BUS_ERROR_NULL; |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 412 | |
| 413 | printf("IPMI Handling GET-SEL-TIME\n"); |
| 414 | |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 415 | auto bus = ipmid_get_sd_bus_connection(); |
| 416 | |
| 417 | auto rct = mapper_get_service(bus, time_manager_obj, &time_provider); |
| 418 | if (rct < 0) { |
| 419 | printf("Error [%s] getting bus name for time provider\n", |
| 420 | strerror(-rct)); |
| 421 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 422 | goto finish; |
| 423 | } |
| 424 | |
| 425 | rct = sd_bus_call_method(bus, |
| 426 | time_provider, |
| 427 | time_manager_obj, |
| 428 | time_manager_intf, |
| 429 | "GetTime", |
| 430 | &bus_error, |
| 431 | &reply, |
| 432 | "s", |
| 433 | "host"); |
| 434 | if (rct < 0) { |
| 435 | printf("Error [%s] getting time\n", strerror(-rct)); |
| 436 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 437 | goto finish; |
| 438 | } |
| 439 | |
| 440 | rct = sd_bus_message_read(reply, "sx", &time_in_str, &host_time_usec); |
| 441 | if (rct < 0) { |
| 442 | fprintf(stderr, "Error [%s] parsing get-time response\n", |
| 443 | strerror(-rct)); |
| 444 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 445 | goto finish; |
| 446 | } |
| 447 | |
| 448 | // Time is really long int but IPMI wants just uint32. This works okay until |
| 449 | // the number of seconds since 1970 overflows uint32 size.. Still a whole |
| 450 | // lot of time here to even think about that. |
| 451 | resp = duration_cast<seconds>(microseconds(host_time_usec)).count(); |
| 452 | resp = htole32(resp); |
| 453 | printf("Host Time read:[%s] :: [%d]\n", time_in_str, resp); |
| 454 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 455 | // From the IPMI Spec 2.0, response should be a 32-bit value |
| 456 | *data_len = sizeof(resp); |
| 457 | |
| 458 | // Pack the actual response |
| 459 | memcpy(response, &resp, *data_len); |
| 460 | |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 461 | finish: |
| 462 | sd_bus_error_free(&bus_error); |
| 463 | reply = sd_bus_message_unref(reply); |
| 464 | free(time_provider); |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 465 | return rc; |
| 466 | } |
| 467 | |
| 468 | ipmi_ret_t ipmi_storage_set_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 469 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 470 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 471 | { |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 472 | char *time_provider = nullptr; |
| 473 | int time_rc = 0; |
| 474 | ipmi_ret_t rc = IPMI_CC_OK; |
| 475 | |
| 476 | sd_bus_message *reply = nullptr; |
| 477 | sd_bus_error bus_error = SD_BUS_ERROR_NULL; |
| 478 | |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 479 | uint32_t* secs = (uint32_t*)request; |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 480 | *data_len = 0; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 481 | |
| 482 | 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] | 483 | printf("Data: 0x%X]\n",*secs); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 484 | |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 485 | auto bus = ipmid_get_sd_bus_connection(); |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 486 | |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 487 | auto rct = mapper_get_service(bus, time_manager_obj, &time_provider); |
| 488 | if (rct < 0) { |
| 489 | printf("Error [%s] getting bus name for time provider\n", |
| 490 | strerror(-rct)); |
| 491 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 492 | goto finish; |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 493 | } |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 494 | |
| 495 | rct = sd_bus_call_method(bus, |
| 496 | time_provider, |
| 497 | time_manager_obj, |
| 498 | time_manager_intf, |
| 499 | "SetTime", |
| 500 | &bus_error, |
| 501 | &reply, |
| 502 | "ss", |
| 503 | "host", |
| 504 | std::to_string(le32toh(*secs)).c_str()); |
| 505 | |
| 506 | if (rct < 0) { |
| 507 | printf("Error [%s] setting time\n", strerror(-rct)); |
| 508 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 509 | goto finish; |
| 510 | } |
| 511 | |
| 512 | rct = sd_bus_message_read(reply, "i", &time_rc); |
| 513 | if (rct < 0) { |
| 514 | fprintf(stderr, "Error [%s] parsing set-time response\n", |
| 515 | strerror(-rct)); |
| 516 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 517 | goto finish; |
| 518 | } |
| 519 | |
| 520 | if (time_rc < 0) { |
| 521 | printf("Error setting time."); |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 522 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 523 | } |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 524 | |
| 525 | finish: |
| 526 | sd_bus_error_free(&bus_error); |
| 527 | reply = sd_bus_message_unref(reply); |
| 528 | free(time_provider); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 529 | return rc; |
| 530 | } |
| 531 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 532 | ipmi_ret_t ipmi_storage_reserve_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 533 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 534 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 535 | { |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 536 | ipmi_ret_t rc = IPMI_CC_OK; |
| 537 | |
Nan Li | 36c0cb6 | 2016-03-31 11:16:08 +0800 | [diff] [blame] | 538 | // IPMI spec, Reservation ID, the value simply increases against each execution of reserve_sel command. |
| 539 | if( ++g_sel_reserve == 0) |
| 540 | g_sel_reserve = 1; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 541 | |
Nan Li | 36c0cb6 | 2016-03-31 11:16:08 +0800 | [diff] [blame] | 542 | printf("IPMI Handling RESERVE-SEL 0x%04x\n", g_sel_reserve); |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 543 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 544 | *data_len = sizeof(g_sel_reserve); |
| 545 | |
| 546 | // Pack the actual response |
| 547 | memcpy(response, &g_sel_reserve, *data_len); |
| 548 | |
| 549 | return rc; |
| 550 | } |
| 551 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 552 | ipmi_ret_t ipmi_storage_add_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 553 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 554 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 555 | { |
| 556 | |
| 557 | ipmi_ret_t rc = IPMI_CC_OK; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 558 | ipmi_add_sel_request_t *p = (ipmi_add_sel_request_t*) request; |
| 559 | uint16_t recordid; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 560 | |
Chris Austen | 313d95b | 2015-10-31 12:55:30 -0500 | [diff] [blame] | 561 | recordid = ((uint16_t)p->eventdata[1] << 8) | p->eventdata[2]; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 562 | |
| 563 | printf("IPMI Handling ADD-SEL for record 0x%04x\n", recordid); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 564 | |
| 565 | *data_len = sizeof(g_sel_reserve); |
| 566 | |
| 567 | // Pack the actual response |
Chris Austen | 7cc3332 | 2015-11-11 00:20:22 -0600 | [diff] [blame] | 568 | memcpy(response, &p->eventdata[1], 2); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 569 | |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 570 | send_esel(recordid); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 571 | |
| 572 | return rc; |
| 573 | } |
| 574 | |
| 575 | |
| 576 | |
| 577 | void register_netfn_storage_functions() |
| 578 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 579 | // <Wildcard Command> |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 580 | 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] | 581 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_WILDCARD, NULL, ipmi_storage_wildcard, |
| 582 | PRIVILEGE_USER); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 583 | |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 584 | // <Get SEL Info> |
| 585 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_GET_SEL_INFO); |
| 586 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_INFO, NULL, getSELInfo, |
| 587 | PRIVILEGE_USER); |
| 588 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 589 | // <Get SEL Time> |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 590 | 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] | 591 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_TIME, NULL, ipmi_storage_get_sel_time, |
| 592 | PRIVILEGE_USER); |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 593 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 594 | // <Set SEL Time> |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 595 | 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] | 596 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_SET_SEL_TIME, NULL, ipmi_storage_set_sel_time, |
| 597 | PRIVILEGE_OPERATOR); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 598 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 599 | // <Reserve SEL> |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 600 | 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] | 601 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_RESERVE_SEL, NULL, ipmi_storage_reserve_sel, |
| 602 | PRIVILEGE_USER); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 603 | |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 604 | // <Get SEL Entry> |
| 605 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY); |
| 606 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY, NULL, getSELEntry, |
| 607 | PRIVILEGE_USER); |
| 608 | |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 609 | // <Delete SEL Entry> |
| 610 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_DELETE_SEL); |
| 611 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_DELETE_SEL, NULL, deleteSELEntry, |
| 612 | PRIVILEGE_OPERATOR); |
| 613 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 614 | // <Add SEL Entry> |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 615 | 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] | 616 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_ADD_SEL, NULL, ipmi_storage_add_sel, |
| 617 | PRIVILEGE_OPERATOR); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame^] | 618 | |
| 619 | // <Clear SEL> |
| 620 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_CLEAR_SEL); |
| 621 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_CLEAR_SEL, NULL, clearSEL, |
| 622 | PRIVILEGE_OPERATOR); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 623 | return; |
| 624 | } |
| 625 | |