1 #include "oem_ibm_handler.hpp" 2 3 #include "file_io_type_lid.hpp" 4 #include "libpldmresponder/file_io.hpp" 5 #include "libpldmresponder/pdr_utils.hpp" 6 7 #include <libpldm/entity.h> 8 #include <libpldm/entity_oem_ibm.h> 9 #include <libpldm/pldm.h> 10 11 #include <phosphor-logging/lg2.hpp> 12 13 PHOSPHOR_LOG2_USING; 14 15 using namespace pldm::pdr; 16 using namespace pldm::utils; 17 18 namespace pldm 19 { 20 namespace responder 21 { 22 namespace oem_ibm_platform 23 { 24 int pldm::responder::oem_ibm_platform::Handler:: 25 getOemStateSensorReadingsHandler( 26 EntityType entityType, EntityInstance entityInstance, 27 StateSetId stateSetId, CompositeCount compSensorCnt, 28 std::vector<get_sensor_state_field>& stateField) 29 { 30 int rc = PLDM_SUCCESS; 31 stateField.clear(); 32 33 for (size_t i = 0; i < compSensorCnt; i++) 34 { 35 uint8_t sensorOpState{}; 36 if (entityType == PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE && 37 stateSetId == PLDM_OEM_IBM_BOOT_STATE) 38 { 39 sensorOpState = fetchBootSide(entityInstance, codeUpdate); 40 } 41 else 42 { 43 rc = PLDM_PLATFORM_INVALID_STATE_VALUE; 44 break; 45 } 46 stateField.push_back({PLDM_SENSOR_ENABLED, PLDM_SENSOR_UNKNOWN, 47 PLDM_SENSOR_UNKNOWN, sensorOpState}); 48 } 49 return rc; 50 } 51 52 int pldm::responder::oem_ibm_platform::Handler:: 53 oemSetStateEffecterStatesHandler( 54 uint16_t entityType, uint16_t entityInstance, uint16_t stateSetId, 55 uint8_t compEffecterCnt, 56 std::vector<set_effecter_state_field>& stateField, 57 uint16_t /*effecterId*/) 58 { 59 int rc = PLDM_SUCCESS; 60 61 for (uint8_t currState = 0; currState < compEffecterCnt; ++currState) 62 { 63 if (stateField[currState].set_request == PLDM_REQUEST_SET) 64 { 65 if (entityType == PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE && 66 stateSetId == PLDM_OEM_IBM_BOOT_STATE) 67 { 68 rc = setBootSide(entityInstance, currState, stateField, 69 codeUpdate); 70 } 71 else if (entityType == PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE && 72 stateSetId == PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE) 73 { 74 if (stateField[currState].effecter_state == 75 uint8_t(CodeUpdateState::START)) 76 { 77 codeUpdate->setCodeUpdateProgress(true); 78 startUpdateEvent = 79 std::make_unique<sdeventplus::source::Defer>( 80 event, 81 std::bind(std::mem_fn(&oem_ibm_platform::Handler:: 82 _processStartUpdate), 83 this, std::placeholders::_1)); 84 } 85 else if (stateField[currState].effecter_state == 86 uint8_t(CodeUpdateState::END)) 87 { 88 rc = PLDM_SUCCESS; 89 assembleImageEvent = std::make_unique< 90 sdeventplus::source::Defer>( 91 event, 92 std::bind( 93 std::mem_fn( 94 &oem_ibm_platform::Handler::_processEndUpdate), 95 this, std::placeholders::_1)); 96 97 // sendCodeUpdateEvent(effecterId, END, START); 98 } 99 else if (stateField[currState].effecter_state == 100 uint8_t(CodeUpdateState::ABORT)) 101 { 102 codeUpdate->setCodeUpdateProgress(false); 103 codeUpdate->clearDirPath(LID_STAGING_DIR); 104 auto sensorId = codeUpdate->getFirmwareUpdateSensor(); 105 sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0, 106 uint8_t(CodeUpdateState::ABORT), 107 uint8_t(CodeUpdateState::START)); 108 // sendCodeUpdateEvent(effecterId, ABORT, END); 109 } 110 else if (stateField[currState].effecter_state == 111 uint8_t(CodeUpdateState::ACCEPT)) 112 { 113 auto sensorId = codeUpdate->getFirmwareUpdateSensor(); 114 sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0, 115 uint8_t(CodeUpdateState::ACCEPT), 116 uint8_t(CodeUpdateState::END)); 117 // TODO Set new Dbus property provided by code update app 118 // sendCodeUpdateEvent(effecterId, ACCEPT, END); 119 } 120 else if (stateField[currState].effecter_state == 121 uint8_t(CodeUpdateState::REJECT)) 122 { 123 auto sensorId = codeUpdate->getFirmwareUpdateSensor(); 124 sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0, 125 uint8_t(CodeUpdateState::REJECT), 126 uint8_t(CodeUpdateState::END)); 127 // TODO Set new Dbus property provided by code update app 128 // sendCodeUpdateEvent(effecterId, REJECT, END); 129 } 130 } 131 else if (entityType == PLDM_ENTITY_SYSTEM_CHASSIS && 132 stateSetId == PLDM_OEM_IBM_SYSTEM_POWER_STATE) 133 { 134 if (stateField[currState].effecter_state == POWER_CYCLE_HARD) 135 { 136 systemRebootEvent = 137 std::make_unique<sdeventplus::source::Defer>( 138 event, 139 std::bind(std::mem_fn(&oem_ibm_platform::Handler:: 140 _processSystemReboot), 141 this, std::placeholders::_1)); 142 } 143 } 144 else 145 { 146 rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE; 147 } 148 } 149 if (rc != PLDM_SUCCESS) 150 { 151 break; 152 } 153 } 154 return rc; 155 } 156 157 void buildAllCodeUpdateEffecterPDR(oem_ibm_platform::Handler* platformHandler, 158 uint16_t entityType, uint16_t entityInstance, 159 uint16_t stateSetID, pdr_utils::Repo& repo) 160 { 161 size_t pdrSize = 0; 162 pdrSize = sizeof(pldm_state_effecter_pdr) + 163 sizeof(state_effecter_possible_states); 164 std::vector<uint8_t> entry{}; 165 entry.resize(pdrSize); 166 pldm_state_effecter_pdr* pdr = 167 reinterpret_cast<pldm_state_effecter_pdr*>(entry.data()); 168 if (!pdr) 169 { 170 error("Failed to get record by PDR type, ERROR:{ERR_CODE}", "ERR_CODE", 171 lg2::hex, 172 static_cast<unsigned>(PLDM_PLATFORM_INVALID_EFFECTER_ID)); 173 return; 174 } 175 pdr->hdr.record_handle = 0; 176 pdr->hdr.version = 1; 177 pdr->hdr.type = PLDM_STATE_EFFECTER_PDR; 178 pdr->hdr.record_change_num = 0; 179 pdr->hdr.length = sizeof(pldm_state_effecter_pdr) - sizeof(pldm_pdr_hdr); 180 pdr->terminus_handle = TERMINUS_HANDLE; 181 pdr->effecter_id = platformHandler->getNextEffecterId(); 182 pdr->entity_type = entityType; 183 pdr->entity_instance = entityInstance; 184 pdr->container_id = 1; 185 pdr->effecter_semantic_id = 0; 186 pdr->effecter_init = PLDM_NO_INIT; 187 pdr->has_description_pdr = false; 188 pdr->composite_effecter_count = 1; 189 190 auto* possibleStatesPtr = pdr->possible_states; 191 auto possibleStates = 192 reinterpret_cast<state_effecter_possible_states*>(possibleStatesPtr); 193 possibleStates->state_set_id = stateSetID; 194 possibleStates->possible_states_size = 2; 195 auto state = 196 reinterpret_cast<state_effecter_possible_states*>(possibleStates); 197 if (stateSetID == PLDM_OEM_IBM_BOOT_STATE) 198 state->states[0].byte = 6; 199 else if (stateSetID == PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE) 200 state->states[0].byte = 126; 201 else if (stateSetID == PLDM_OEM_IBM_SYSTEM_POWER_STATE) 202 state->states[0].byte = 2; 203 pldm::responder::pdr_utils::PdrEntry pdrEntry{}; 204 pdrEntry.data = entry.data(); 205 pdrEntry.size = pdrSize; 206 repo.addRecord(pdrEntry); 207 } 208 209 void buildAllCodeUpdateSensorPDR(oem_ibm_platform::Handler* platformHandler, 210 uint16_t entityType, uint16_t entityInstance, 211 uint16_t stateSetID, pdr_utils::Repo& repo) 212 { 213 size_t pdrSize = 0; 214 pdrSize = 215 sizeof(pldm_state_sensor_pdr) + sizeof(state_sensor_possible_states); 216 std::vector<uint8_t> entry{}; 217 entry.resize(pdrSize); 218 pldm_state_sensor_pdr* pdr = 219 reinterpret_cast<pldm_state_sensor_pdr*>(entry.data()); 220 if (!pdr) 221 { 222 error("Failed to get record by PDR type, ERROR:{ERR_CODE}", "ERR_CODE", 223 lg2::hex, static_cast<unsigned>(PLDM_PLATFORM_INVALID_SENSOR_ID)); 224 return; 225 } 226 pdr->hdr.record_handle = 0; 227 pdr->hdr.version = 1; 228 pdr->hdr.type = PLDM_STATE_SENSOR_PDR; 229 pdr->hdr.record_change_num = 0; 230 pdr->hdr.length = sizeof(pldm_state_sensor_pdr) - sizeof(pldm_pdr_hdr); 231 pdr->terminus_handle = TERMINUS_HANDLE; 232 pdr->sensor_id = platformHandler->getNextSensorId(); 233 pdr->entity_type = entityType; 234 pdr->entity_instance = entityInstance; 235 pdr->container_id = 1; 236 pdr->sensor_init = PLDM_NO_INIT; 237 pdr->sensor_auxiliary_names_pdr = false; 238 pdr->composite_sensor_count = 1; 239 240 auto* possibleStatesPtr = pdr->possible_states; 241 auto possibleStates = 242 reinterpret_cast<state_sensor_possible_states*>(possibleStatesPtr); 243 possibleStates->state_set_id = stateSetID; 244 possibleStates->possible_states_size = 2; 245 auto state = 246 reinterpret_cast<state_sensor_possible_states*>(possibleStates); 247 if ((stateSetID == PLDM_OEM_IBM_BOOT_STATE) || 248 (stateSetID == PLDM_OEM_IBM_VERIFICATION_STATE)) 249 state->states[0].byte = 6; 250 else if (stateSetID == PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE) 251 state->states[0].byte = 126; 252 pldm::responder::pdr_utils::PdrEntry pdrEntry{}; 253 pdrEntry.data = entry.data(); 254 pdrEntry.size = pdrSize; 255 repo.addRecord(pdrEntry); 256 } 257 258 void pldm::responder::oem_ibm_platform::Handler::buildOEMPDR( 259 pdr_utils::Repo& repo) 260 { 261 buildAllCodeUpdateEffecterPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, 262 ENTITY_INSTANCE_0, PLDM_OEM_IBM_BOOT_STATE, 263 repo); 264 buildAllCodeUpdateEffecterPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, 265 ENTITY_INSTANCE_1, PLDM_OEM_IBM_BOOT_STATE, 266 repo); 267 buildAllCodeUpdateEffecterPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, 268 ENTITY_INSTANCE_0, 269 PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE, repo); 270 buildAllCodeUpdateEffecterPDR(this, PLDM_ENTITY_SYSTEM_CHASSIS, 271 ENTITY_INSTANCE_1, 272 PLDM_OEM_IBM_SYSTEM_POWER_STATE, repo); 273 274 buildAllCodeUpdateSensorPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, 275 ENTITY_INSTANCE_0, PLDM_OEM_IBM_BOOT_STATE, 276 repo); 277 buildAllCodeUpdateSensorPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, 278 ENTITY_INSTANCE_1, PLDM_OEM_IBM_BOOT_STATE, 279 repo); 280 buildAllCodeUpdateSensorPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, 281 ENTITY_INSTANCE_0, 282 PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE, repo); 283 buildAllCodeUpdateSensorPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, 284 ENTITY_INSTANCE_0, 285 PLDM_OEM_IBM_VERIFICATION_STATE, repo); 286 auto sensorId = findStateSensorId( 287 repo.getPdr(), 0, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, 288 ENTITY_INSTANCE_0, 1, PLDM_OEM_IBM_VERIFICATION_STATE); 289 codeUpdate->setMarkerLidSensor(sensorId); 290 sensorId = findStateSensorId( 291 repo.getPdr(), 0, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, 292 ENTITY_INSTANCE_0, 1, PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE); 293 codeUpdate->setFirmwareUpdateSensor(sensorId); 294 } 295 296 void pldm::responder::oem_ibm_platform::Handler::setPlatformHandler( 297 pldm::responder::platform::Handler* handler) 298 { 299 platformHandler = handler; 300 } 301 302 int pldm::responder::oem_ibm_platform::Handler::sendEventToHost( 303 std::vector<uint8_t>& requestMsg, uint8_t instanceId) 304 { 305 if (requestMsg.size()) 306 { 307 std::ostringstream tempStream; 308 for (int byte : requestMsg) 309 { 310 tempStream << std::setfill('0') << std::setw(2) << std::hex << byte 311 << " "; 312 } 313 std::cout << tempStream.str() << std::endl; 314 } 315 auto oemPlatformEventMessageResponseHandler = [](mctp_eid_t /*eid*/, 316 const pldm_msg* response, 317 size_t respMsgLen) { 318 uint8_t completionCode{}; 319 uint8_t status{}; 320 auto rc = decode_platform_event_message_resp(response, respMsgLen, 321 &completionCode, &status); 322 if (rc || completionCode) 323 { 324 error( 325 "Failed to decode_platform_event_message_resp: for code update event rc={RC}, cc={CC}", 326 "RC", rc, "CC", static_cast<unsigned>(completionCode)); 327 } 328 }; 329 auto rc = handler->registerRequest( 330 mctp_eid, instanceId, PLDM_PLATFORM, PLDM_PLATFORM_EVENT_MESSAGE, 331 std::move(requestMsg), 332 std::move(oemPlatformEventMessageResponseHandler)); 333 if (rc) 334 { 335 error("Failed to send BIOS attribute change event message "); 336 } 337 338 return rc; 339 } 340 341 int encodeEventMsg(uint8_t eventType, const std::vector<uint8_t>& eventDataVec, 342 std::vector<uint8_t>& requestMsg, uint8_t instanceId) 343 { 344 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); 345 346 auto rc = encode_platform_event_message_req( 347 instanceId, 1 /*formatVersion*/, TERMINUS_ID /*tId*/, eventType, 348 eventDataVec.data(), eventDataVec.size(), request, 349 eventDataVec.size() + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES); 350 351 return rc; 352 } 353 354 void pldm::responder::oem_ibm_platform::Handler::sendStateSensorEvent( 355 uint16_t sensorId, enum sensor_event_class_states sensorEventClass, 356 uint8_t sensorOffset, uint8_t eventState, uint8_t prevEventState) 357 { 358 std::vector<uint8_t> sensorEventDataVec{}; 359 size_t sensorEventSize = PLDM_SENSOR_EVENT_DATA_MIN_LENGTH + 1; 360 sensorEventDataVec.resize(sensorEventSize); 361 auto eventData = reinterpret_cast<struct pldm_sensor_event_data*>( 362 sensorEventDataVec.data()); 363 eventData->sensor_id = sensorId; 364 eventData->sensor_event_class_type = sensorEventClass; 365 auto eventClassStart = eventData->event_class; 366 auto eventClass = 367 reinterpret_cast<struct pldm_sensor_event_state_sensor_state*>( 368 eventClassStart); 369 eventClass->sensor_offset = sensorOffset; 370 eventClass->event_state = eventState; 371 eventClass->previous_event_state = prevEventState; 372 auto instanceId = requester.getInstanceId(mctp_eid); 373 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) + 374 PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + 375 sensorEventDataVec.size()); 376 auto rc = encodeEventMsg(PLDM_SENSOR_EVENT, sensorEventDataVec, requestMsg, 377 instanceId); 378 if (rc != PLDM_SUCCESS) 379 { 380 error("Failed to encode state sensor event, rc = {RC}", "RC", rc); 381 requester.markFree(mctp_eid, instanceId); 382 return; 383 } 384 rc = sendEventToHost(requestMsg, instanceId); 385 if (rc != PLDM_SUCCESS) 386 { 387 error("Failed to send event to host: rc={RC}", "RC", rc); 388 } 389 return; 390 } 391 392 void pldm::responder::oem_ibm_platform::Handler::_processEndUpdate( 393 sdeventplus::source::EventBase& /*source */) 394 { 395 assembleImageEvent.reset(); 396 int retc = codeUpdate->assembleCodeUpdateImage(); 397 if (retc != PLDM_SUCCESS) 398 { 399 codeUpdate->setCodeUpdateProgress(false); 400 auto sensorId = codeUpdate->getFirmwareUpdateSensor(); 401 sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0, 402 uint8_t(CodeUpdateState::FAIL), 403 uint8_t(CodeUpdateState::START)); 404 } 405 } 406 407 void pldm::responder::oem_ibm_platform::Handler::_processStartUpdate( 408 sdeventplus::source::EventBase& /*source */) 409 { 410 codeUpdate->deleteImage(); 411 CodeUpdateState state = CodeUpdateState::START; 412 auto rc = codeUpdate->setRequestedApplyTime(); 413 if (rc != PLDM_SUCCESS) 414 { 415 error("setRequestedApplyTime failed"); 416 state = CodeUpdateState::FAIL; 417 } 418 auto sensorId = codeUpdate->getFirmwareUpdateSensor(); 419 sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0, uint8_t(state), 420 uint8_t(CodeUpdateState::END)); 421 } 422 423 void pldm::responder::oem_ibm_platform::Handler::_processSystemReboot( 424 sdeventplus::source::EventBase& /*source */) 425 { 426 pldm::utils::PropertyValue value = 427 "xyz.openbmc_project.State.Chassis.Transition.Off"; 428 pldm::utils::DBusMapping dbusMapping{"/xyz/openbmc_project/state/chassis0", 429 "xyz.openbmc_project.State.Chassis", 430 "RequestedPowerTransition", "string"}; 431 try 432 { 433 dBusIntf->setDbusProperty(dbusMapping, value); 434 } 435 catch (const std::exception& e) 436 { 437 error( 438 "Chassis State transition to Off failed, unable to set property RequestedPowerTransition ERROR={ERR_EXCEP}", 439 "ERR_EXCEP", e.what()); 440 } 441 442 using namespace sdbusplus::bus::match::rules; 443 chassisOffMatch = std::make_unique<sdbusplus::bus::match_t>( 444 pldm::utils::DBusHandler::getBus(), 445 propertiesChanged("/xyz/openbmc_project/state/chassis0", 446 "xyz.openbmc_project.State.Chassis"), 447 [this](sdbusplus::message_t& msg) { 448 DbusChangedProps props{}; 449 std::string intf; 450 msg.read(intf, props); 451 const auto itr = props.find("CurrentPowerState"); 452 if (itr != props.end()) 453 { 454 PropertyValue value = itr->second; 455 auto propVal = std::get<std::string>(value); 456 if (propVal == 457 "xyz.openbmc_project.State.Chassis.PowerState.Off") 458 { 459 pldm::utils::DBusMapping dbusMapping{ 460 "/xyz/openbmc_project/control/host0/" 461 "power_restore_policy/one_time", 462 "xyz.openbmc_project.Control.Power.RestorePolicy", 463 "PowerRestorePolicy", "string"}; 464 value = "xyz.openbmc_project.Control.Power.RestorePolicy." 465 "Policy.AlwaysOn"; 466 try 467 { 468 dBusIntf->setDbusProperty(dbusMapping, value); 469 } 470 catch (const std::exception& e) 471 { 472 error( 473 "Setting one-time restore policy failed, unable to set property PowerRestorePolicy ERROR={ERR_EXCEP}", 474 "ERR_EXCEP", e.what()); 475 } 476 dbusMapping = pldm::utils::DBusMapping{ 477 "/xyz/openbmc_project/state/bmc0", 478 "xyz.openbmc_project.State.BMC", 479 "RequestedBMCTransition", "string"}; 480 value = "xyz.openbmc_project.State.BMC.Transition.Reboot"; 481 try 482 { 483 dBusIntf->setDbusProperty(dbusMapping, value); 484 } 485 catch (const std::exception& e) 486 { 487 error( 488 "BMC state transition to reboot failed, unable to set property RequestedBMCTransition ERROR={ERR_EXCEP}", 489 "ERR_EXCEP", e.what()); 490 } 491 } 492 } 493 }); 494 } 495 496 void pldm::responder::oem_ibm_platform::Handler::checkAndDisableWatchDog() 497 { 498 if (!hostOff && setEventReceiverCnt == SET_EVENT_RECEIVER_SENT) 499 { 500 disableWatchDogTimer(); 501 } 502 503 return; 504 } 505 506 bool pldm::responder::oem_ibm_platform::Handler::watchDogRunning() 507 { 508 static constexpr auto watchDogObjectPath = 509 "/xyz/openbmc_project/watchdog/host0"; 510 static constexpr auto watchDogEnablePropName = "Enabled"; 511 static constexpr auto watchDogInterface = 512 "xyz.openbmc_project.State.Watchdog"; 513 bool isWatchDogRunning = false; 514 try 515 { 516 isWatchDogRunning = pldm::utils::DBusHandler().getDbusProperty<bool>( 517 watchDogObjectPath, watchDogEnablePropName, watchDogInterface); 518 } 519 catch (const std::exception& e) 520 { 521 return false; 522 } 523 return isWatchDogRunning; 524 } 525 526 void pldm::responder::oem_ibm_platform::Handler::resetWatchDogTimer() 527 { 528 static constexpr auto watchDogService = "xyz.openbmc_project.Watchdog"; 529 static constexpr auto watchDogObjectPath = 530 "/xyz/openbmc_project/watchdog/host0"; 531 static constexpr auto watchDogInterface = 532 "xyz.openbmc_project.State.Watchdog"; 533 static constexpr auto watchDogResetPropName = "ResetTimeRemaining"; 534 535 bool wdStatus = watchDogRunning(); 536 if (wdStatus == false) 537 { 538 return; 539 } 540 try 541 { 542 auto& bus = pldm::utils::DBusHandler::getBus(); 543 auto resetMethod = 544 bus.new_method_call(watchDogService, watchDogObjectPath, 545 watchDogInterface, watchDogResetPropName); 546 resetMethod.append(true); 547 bus.call_noreply(resetMethod); 548 } 549 catch (const std::exception& e) 550 { 551 error("Failed To reset watchdog timer ERROR={ERR_EXCEP}", "ERR_EXCEP", 552 e.what()); 553 return; 554 } 555 } 556 557 void pldm::responder::oem_ibm_platform::Handler::disableWatchDogTimer() 558 { 559 setEventReceiverCnt = 0; 560 pldm::utils::DBusMapping dbusMapping{"/xyz/openbmc_project/watchdog/host0", 561 "xyz.openbmc_project.State.Watchdog", 562 "Enabled", "bool"}; 563 bool wdStatus = watchDogRunning(); 564 565 if (!wdStatus) 566 { 567 return; 568 } 569 try 570 { 571 pldm::utils::DBusHandler().setDbusProperty(dbusMapping, false); 572 } 573 catch (const std::exception& e) 574 { 575 error("Failed To disable watchdog timer ERROR={ERR_EXCEP}", "ERR_EXCEP", 576 e.what()); 577 } 578 } 579 int pldm::responder::oem_ibm_platform::Handler::checkBMCState() 580 { 581 try 582 { 583 pldm::utils::PropertyValue propertyValue = 584 pldm::utils::DBusHandler().getDbusPropertyVariant( 585 "/xyz/openbmc_project/state/bmc0", "CurrentBMCState", 586 "xyz.openbmc_project.State.BMC"); 587 588 if (std::get<std::string>(propertyValue) == 589 "xyz.openbmc_project.State.BMC.BMCState.NotReady") 590 { 591 error("GetPDR : PLDM stack is not ready for PDR exchange"); 592 return PLDM_ERROR_NOT_READY; 593 } 594 } 595 catch (const std::exception& e) 596 { 597 error("Error getting the current BMC state"); 598 return PLDM_ERROR; 599 } 600 return PLDM_SUCCESS; 601 } 602 603 } // namespace oem_ibm_platform 604 } // namespace responder 605 } // namespace pldm 606