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/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