bmc_state_manager: Add HardReboot support to BMC

Add HardReboot support to BMC for ForceRestart
Below is patch supporting this change.
https://gerrit.openbmc-project.xyz/#/c/openbmc/bmcweb/+/33695

Tested:
1. On Redfish can use ForceRestart to HardReboot the BMC.
2. Verified using Redfish url.
3. Verified using busctl call.
Command:
busctl call xyz.openbmc_project.State.BMC
/xyz/openbmc_project/state/bmc0 org.freedesktop.DBus.Properties
Set ssv xyz.openbmc_project.State.BMC RequestedBMCTransition s
xyz.openbmc_project.State.BMC.Transition.HardReboot

Results: BMC hard rebooted successfully.

Signed-off-by: Jayaprakash Mutyala <mutyalax.jayaprakash@intel.com>
Change-Id: Ie646ba84c066b43638be5efcd94622a0af8c33b8
diff --git a/bmc_state_manager.cpp b/bmc_state_manager.cpp
index 26deec9..3fbe4bf 100644
--- a/bmc_state_manager.cpp
+++ b/bmc_state_manager.cpp
@@ -131,29 +131,48 @@
 
 void BMC::executeTransition(const Transition tranReq)
 {
-    // Check to make sure it can be found
-    auto iter = SYSTEMD_TABLE.find(tranReq);
-    if (iter == SYSTEMD_TABLE.end())
-        return;
-
-    const auto& sysdUnit = iter->second;
-
-    auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
-                                            SYSTEMD_INTERFACE, "StartUnit");
-    // The only valid transition is reboot and that
-    // needs to be irreversible once started
-    method.append(sysdUnit, "replace-irreversibly");
-
-    try
+    // HardReboot does not shutdown any services and immediately transitions
+    // into the reboot process
+    if (server::BMC::Transition::HardReboot == tranReq)
     {
-        this->bus.call(method);
+        auto method = this->bus.new_method_call(
+            SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH, SYSTEMD_INTERFACE, "Reboot");
+        try
+        {
+            this->bus.call(method);
+        }
+        catch (const SdBusError& e)
+        {
+            log<level::INFO>("Error in HardReboot",
+                             entry("ERROR=%s", e.what()));
+        }
     }
-    catch (const SdBusError& e)
+    else
     {
-        log<level::INFO>("Error in StartUnit - replace-irreversibly",
-                         entry("ERROR=%s", e.what()));
-    }
+        // Check to make sure it can be found
+        auto iter = SYSTEMD_TABLE.find(tranReq);
+        if (iter == SYSTEMD_TABLE.end())
+            return;
 
+        const auto& sysdUnit = iter->second;
+
+        auto method = this->bus.new_method_call(
+            SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH, SYSTEMD_INTERFACE, "StartUnit");
+        // The only valid transition is reboot and that
+        // needs to be irreversible once started
+
+        method.append(sysdUnit, "replace-irreversibly");
+
+        try
+        {
+            this->bus.call(method);
+        }
+        catch (const SdBusError& e)
+        {
+            log<level::INFO>("Error in StartUnit - replace-irreversibly",
+                             entry("ERROR=%s", e.what()));
+        }
+    }
     return;
 }