mmc: reset: Clear the HMC-managed bios attr

Set the pvm_hmc_managed bios attribute to Disabled during a factory
reset to clear the indicator that says the system is HMC managed since a
factory reset is expected to remove the HMC information. The reset
function is already deleting the HMC save area directory created by
bmcweb.

Tested: Set the pvm_hmc_managed attribute to Enabled, then verified that
after a bios factory reset it's set to Disabled.

Change-Id: I2cbe9baaebb4a11b612f0940ff2a994a8474d3d6
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/mmc/item_updater_mmc.cpp b/mmc/item_updater_mmc.cpp
index 04f237d..1a5b142 100644
--- a/mmc/item_updater_mmc.cpp
+++ b/mmc/item_updater_mmc.cpp
@@ -3,6 +3,7 @@
 #include "item_updater_mmc.hpp"
 
 #include "activation_mmc.hpp"
+#include "utils.hpp"
 #include "version.hpp"
 
 #include <filesystem>
@@ -70,6 +71,9 @@
     }
 
     // Remove files related to the Hardware Management Console / BMC web app
+
+    utils::clearHMCManaged(bus);
+
     std::filesystem::path consolePath("/var/lib/bmcweb/ibm-management-console");
     if (std::filesystem::exists(consolePath))
     {
@@ -90,7 +94,6 @@
                                     "pldm-reset-phyp-nvram.service",
                                     "pldm-reset-phyp-nvram-cksum.service"};
 
-    auto bus = sdbusplus::bus::new_default();
     for (const auto& service : services)
     {
         auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
diff --git a/utils.cpp b/utils.cpp
index 85c650e..a994b33 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -112,4 +112,36 @@
     }
 }
 
+void clearHMCManaged(sdbusplus::bus::bus& bus)
+{
+    constexpr auto biosConfigPath = "/xyz/openbmc_project/bios_config/manager";
+    constexpr auto biosConfigIntf = "xyz.openbmc_project.BIOSConfig.Manager";
+    constexpr auto dbusAttrType =
+        "xyz.openbmc_project.BIOSConfig.Manager.AttributeType.Enumeration";
+    constexpr auto dbusAttrName = "pvm_hmc_managed";
+
+    using PendingAttributesType = std::vector<std::pair<
+        std::string, std::tuple<std::string, std::variant<std::string>>>>;
+    PendingAttributesType pendingAttributes;
+    pendingAttributes.emplace_back(std::make_pair(
+        dbusAttrName, std::make_tuple(dbusAttrType, "Disabled")));
+
+    try
+    {
+        auto service = getService(bus, biosConfigPath, biosConfigIntf);
+        auto method = bus.new_method_call(service.c_str(), biosConfigPath,
+                                          SYSTEMD_PROPERTY_INTERFACE, "Set");
+        method.append(biosConfigIntf, "PendingAttributes",
+                      std::variant<PendingAttributesType>(pendingAttributes));
+        bus.call(method);
+    }
+    catch (const sdbusplus::exception::exception& e)
+    {
+        log<level::ERR>("Error setting the bios attribute",
+                        entry("ERROR=%s", e.what()),
+                        entry("ATTRIBUTE=%s", dbusAttrName));
+        return;
+    }
+}
+
 } // namespace utils
diff --git a/utils.hpp b/utils.hpp
index acb44ca..8ff2370 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -45,6 +45,13 @@
  */
 void hiomapdResume(sdbusplus::bus::bus& bus);
 
+/** @brief Set the Hardware Management Console Managed bios attribute to
+ *         Disabled to clear the indication that the system is HMC-managed.
+ *
+ * @param[in] bus - The D-Bus bus object.
+ */
+void clearHMCManaged(sdbusplus::bus::bus& bus);
+
 } // namespace utils
 
 #endif // OPENSSL_VERSION_NUMBER < 0x10100000L