oem_ibm: Reset Watchdog Timer

The watchdog timer is started as soon as the BMC
is powered on. Host sends GetTID to BMC, BMC
responds to that and sends SetEventReceiver
command with a specified time interval(Heartbeat). Host
is supposed to send PlatformEventMessage to BMC
within the elapsed interval.

We use the same infrastructure as that of surveillance
for implementing host watchdog. The difference between
surveillance and host watchdog is that-
-> Surveillance is host monitoring the BMC if it is
   functioning and its us up and running and if the BMC
   fails to respond to ping from host, then host will
   reset the BMC
-> Watchdog is BMC monitoring if the host boots without
   failures, and if host does not respond to pings from
   BMC after the watchdog interval, then the watchdog app
   triggers a host dump.

Watchdog monitoring is followed by surveillance.

This commit adds change to reset the watchdog
timer on receiving PlatformEventMessage for
heartbeat elapsed time from Host

Tester with pldmtool:
./pldmtool raw -d 0x80 0x02 0x0A 0x01 0x01 0x06 0x01 0x01
Request Message:
08 01 80 02 0a 01 01 06 01 01
Received Msg
08 01 80 02 0a 01 01 06 01 01
Sending Msg
00 02 0a 00 00
Received Msg
08 01 00 02 0a 00 00
Response Message:
08 01 00 02 0a 00 00

Signed-off-by: Sagar Srinivas <sagar.srinivas@ibm.com>
Change-Id: I9fea658c3f2d3086ad2574ef827a5154dac6960e
diff --git a/oem/ibm/libpldmresponder/oem_ibm_handler.cpp b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
index 71393cb..b3b1961 100644
--- a/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
+++ b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
@@ -491,6 +491,57 @@
             }
         });
 }
+
+bool pldm::responder::oem_ibm_platform::Handler::watchDogRunning()
+{
+    static constexpr auto watchDogObjectPath =
+        "/xyz/openbmc_project/watchdog/host0";
+    static constexpr auto watchDogEnablePropName = "Enabled";
+    static constexpr auto watchDogInterface =
+        "xyz.openbmc_project.State.Watchdog";
+    bool isWatchDogRunning = false;
+    try
+    {
+        isWatchDogRunning = pldm::utils::DBusHandler().getDbusProperty<bool>(
+            watchDogObjectPath, watchDogEnablePropName, watchDogInterface);
+    }
+    catch (const std::exception& e)
+    {
+        return false;
+    }
+    return isWatchDogRunning;
+}
+
+void pldm::responder::oem_ibm_platform::Handler::resetWatchDogTimer()
+{
+    static constexpr auto watchDogService = "xyz.openbmc_project.Watchdog";
+    static constexpr auto watchDogObjectPath =
+        "/xyz/openbmc_project/watchdog/host0";
+    static constexpr auto watchDogInterface =
+        "xyz.openbmc_project.State.Watchdog";
+    static constexpr auto watchDogResetPropName = "ResetTimeRemaining";
+
+    bool wdStatus = watchDogRunning();
+    if (wdStatus == false)
+    {
+        return;
+    }
+    try
+    {
+        auto& bus = pldm::utils::DBusHandler::getBus();
+        auto resetMethod =
+            bus.new_method_call(watchDogService, watchDogObjectPath,
+                                watchDogInterface, watchDogResetPropName);
+        resetMethod.append(true);
+        bus.call_noreply(resetMethod);
+    }
+    catch (const std::exception& e)
+    {
+        std::cerr << "Failed To reset watchdog timer"
+                  << "ERROR=" << e.what() << std::endl;
+        return;
+    }
+}
 } // namespace oem_ibm_platform
 } // namespace responder
 } // namespace pldm