watchdog: Implement error on reset of disabled watchdog

This enables the host to recover when the BMC resets or the daemon loses
state for some reason. A well formed host will resend the SetTimeout
command if it encounters this error code.

Change-Id: Ib5fd50ac3ad83ef820f0209354aa8f084a563995
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/app/watchdog.cpp b/app/watchdog.cpp
index 84e8426..7b04faa 100644
--- a/app/watchdog.cpp
+++ b/app/watchdog.cpp
@@ -124,7 +124,8 @@
     int r = 0;
     char *busname = NULL;
 
-    // Current time interval that is set in watchdog.
+    // Current properties of the watchdog daemon.
+    bool enabled = false;
     uint64_t interval = 0;
 
     // Status code.
@@ -140,6 +141,34 @@
         goto finish;
     }
 
+    // Check if our watchdog is running
+    r = sd_bus_call_method(bus, busname, objname, property_iface,
+                           "Get", &error, &reply, "ss",
+                           iface, "Enabled");
+    if(r < 0) {
+        fprintf(stderr, "Failed to get current Enabled msg: %s\n",
+                strerror(-r));
+        goto finish;
+    }
+
+    // Now extract the value
+    r = sd_bus_message_read(reply, "v", "b", &enabled);
+    if (r < 0) {
+        fprintf(stderr, "Failed to read current Enabled: %s\n",
+                strerror(-r));
+        goto finish;
+    }
+
+    // If we are not enable we should indicate that
+    if (!enabled) {
+        printf("Watchdog not enabled during reset\n");
+        rc = IPMI_WDOG_CC_NOT_INIT;
+        goto finish;
+    }
+
+    sd_bus_error_free(&error);
+    reply = sd_bus_message_unref(reply);
+
     // Get the current interval and set it back.
     r = sd_bus_call_method(bus, busname, objname, property_iface,
                            "Get", &error, &reply, "ss",
diff --git a/host-ipmid/ipmid-api.h b/host-ipmid/ipmid-api.h
index 5539f9c..5f7bac3 100644
--- a/host-ipmid/ipmid-api.h
+++ b/host-ipmid/ipmid-api.h
@@ -111,6 +111,7 @@
 {
     IPMI_CC_OK = 0x00,
     IPMI_DCMI_CC_NO_ACTIVE_POWER_LIMIT = 0x80,
+    IPMI_WDOG_CC_NOT_INIT = 0x80,
     IPMI_CC_INVALID = 0xC1,
     IPMI_CC_INVALID_RESERVATION_ID = 0xC5,
     IPMI_CC_REQ_DATA_LEN_INVALID = 0xC7,