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