Decrement reboot counter on all boot attempts

OpenBMC will control the default amount of boot attemps
allowed on systems. If an external entity requests to
set the boot count, it will be treated as a command
to reset the boot count to the OpenBMC configured
default.

Resolves openbmc/openbmc#1676
Resolves openbmc/openbmc#1646

Change-Id: I7d03272d174685a72e1bdff4d7e2142fc69b7edf
Signed-off-by: Andrew Geissler <andrewg@us.ibm.com>
diff --git a/host_state_manager.hpp b/host_state_manager.hpp
index 41310d6..af748f5 100644
--- a/host_state_manager.hpp
+++ b/host_state_manager.hpp
@@ -3,6 +3,7 @@
 #include <string>
 #include <functional>
 #include <sdbusplus/bus.hpp>
+#include <phosphor-logging/log.hpp>
 #include <xyz/openbmc_project/State/Boot/Progress/server.hpp>
 #include <xyz/openbmc_project/Control/Boot/RebootAttempts/server.hpp>
 #include <xyz/openbmc_project/State/OperatingSystem/Status/server.hpp>
@@ -23,6 +24,8 @@
         sdbusplus::xyz::openbmc_project::Control::Boot::server::RebootAttempts,
         sdbusplus::xyz::openbmc_project::State::OperatingSystem::server::Status>;
 
+using namespace phosphor::logging;
+
 namespace sdbusRule = sdbusplus::bus::match::rules;
 
 /** @class Host
@@ -77,6 +80,28 @@
         /** @brief Set value of CurrentHostState */
         HostState currentHostState(HostState value) override;
 
+        /**
+         * @brief Set host reboot count to default
+         *
+         * OpenBMC software controls the number of allowed reboot attempts so
+         * any external set request of this property will be overridden by
+         * this function and set to the default.
+         *
+         * The only code responsible for decrementing the boot count resides
+         * within this process and that will use the sub class interface
+         * directly
+         *
+         * @param[in] value      - Reboot count value, will be ignored
+         *
+         * @return Default number of reboot attempts left
+         */
+        uint32_t attemptsLeft(uint32_t value) override
+        {
+            log<level::DEBUG>("External request to reset reboot count");
+            return (sdbusplus::xyz::openbmc_project::Control::Boot::server::
+                    RebootAttempts::attemptsLeft(BOOT_COUNT_MAX_ALLOWED));
+        }
+
     private:
         /**
          * @brief subscribe to the systemd signals
@@ -138,6 +163,16 @@
          */
         bool getStateRestoreSetting() const;
 
+        /** @brief Decrement reboot count
+         *
+         * This is used internally to this application to decrement the boot
+         * count on each boot attempt. The host will use the external
+         * attemptsLeft() interface to reset the count when a boot is successful
+         *
+         * @return number of reboot count attempts left
+         */
+        uint32_t decrementRebootCount();
+
         /** @brief Persistent sdbusplus DBus bus connection. */
         sdbusplus::bus::bus& bus;