Fix: Ignore reverting for validation unsecure mode

Ignore reverting executed manufacturing command behavior when
in validation unsecure mode. In that mode, just preserve the
set value as such till BMC is rebooted.

Tested:
1. Verified by setting a FAN to 100 % PWM and it stays even after 15
minutes as expected.

Change-Id: I426f69d129dab0b04571afd4fde043119bc5e26b
Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
diff --git a/include/manufacturingcommands.hpp b/include/manufacturingcommands.hpp
index e7a1cc8..3594abb 100644
--- a/include/manufacturingcommands.hpp
+++ b/include/manufacturingcommands.hpp
@@ -70,6 +70,15 @@
 static constexpr const char* specialModeIntf =
     "xyz.openbmc_project.Security.SpecialMode";
 
+enum class SpecialMode : uint8_t
+{
+    none = 0,
+    mfg = 1,
+#ifdef BMC_VALIDATION_UNSECURE_FEATURE
+    valUnsecure = 2
+#endif
+};
+
 enum class SmActionGet : uint8_t
 {
     sample = 0,
@@ -251,29 +260,29 @@
 
     void revertTimerHandler();
 
-    bool isMfgMode(void)
+    SpecialMode getMfgMode(void)
     {
         ipmi::Value mode;
         if (getProperty(specialModeService, specialModeObjPath, specialModeIntf,
                         "SpecialMode", &mode) != 0)
         {
-            return false;
+            return SpecialMode::none;
         }
         if (std::get<std::string>(mode) ==
             "xyz.openbmc_project.Control.Security.SpecialMode.Modes."
             "Manufacturing")
         {
-            return true;
+            return SpecialMode::mfg;
         }
 #ifdef BMC_VALIDATION_UNSECURE_FEATURE
         if (std::get<std::string>(mode) ==
             "xyz.openbmc_project.Control.Security.SpecialMode.Modes."
             "ValidationUnsecure")
         {
-            return true;
+            return SpecialMode::valUnsecure;
         }
 #endif
-        return false;
+        return SpecialMode::none;
     }
 
     bool revertFanPWM = false;
diff --git a/src/manufacturingcommands.cpp b/src/manufacturingcommands.cpp
index d8b49dc..f2f8a58 100644
--- a/src/manufacturingcommands.cpp
+++ b/src/manufacturingcommands.cpp
@@ -176,6 +176,14 @@
 
 void Manufacturing::revertTimerHandler()
 {
+
+#ifdef BMC_VALIDATION_UNSECURE_FEATURE
+    if (mtm.getMfgMode() == SpecialMode::valUnsecure)
+    {
+        // Don't revert the behaviour for validation unsecure mode.
+        return;
+    }
+#endif
     if (revertFanPWM)
     {
         revertFanPWM = false;
@@ -762,8 +770,8 @@
         case makeCmdKey(ipmi::netFnApp, ipmi::app::cmdMasterWriteRead):
             if (request->payload.size() > 4)
             {
-                // Allow write data count > 1, only if it is in MFG mode
-                if (!mtm.isMfgMode())
+                // Allow write data count > 1 only in Special mode
+                if (mtm.getMfgMode() == SpecialMode::none)
                 {
                     return ipmi::ccInsufficientPrivilege;
                 }
@@ -781,8 +789,8 @@
                         ipmi::intel::general::cmdGetManufacturingData):
         case makeCmdKey(ipmi::netFnStorage, ipmi::storage::cmdWriteFruData):
 
-            // Check for MTM mode
-            if (!mtm.isMfgMode())
+            // Check for Special mode
+            if (mtm.getMfgMode() == SpecialMode::none)
             {
                 return ipmi::ccInvalidCommand;
             }
@@ -917,10 +925,10 @@
     }
 
     // Allow single byte write as it is offset byte to read the data, rest allow
-    // only in MFG mode.
+    // only in Special mode.
     if (writeCount > 1)
     {
-        if (!mtm.isMfgMode())
+        if (mtm.getMfgMode() == SpecialMode::none)
         {
             return ipmi::responseInsufficientPrivilege();
         }
@@ -961,7 +969,7 @@
     std::vector<uint8_t> writeData = {0x60, 0x1};
     std::vector<uint8_t> readBuf(0);
 
-    if (!mtm.isMfgMode())
+    if (mtm.getMfgMode() == SpecialMode::none)
     {
         return ipmi::responseInsufficientPrivilege();
     }