Use correct OSStatus in biosconfigcommands to detect post completed.

biosconfigcommands was checking for "OperatingState" as value of
interface xyz.openbmc_project.State.OperatingSystem.Status, but
"OperatingState" is not in list of valid enum in OSStatus.

Fix: use "Standby" or
"xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Standby"

Tested
By sending following OOB BIOS commands:
1) Set Payload (0xD5), for type payload type 0.
2) Set BIOS Password Hash info (D7).
3) Set BIOS Feature Capability (D3).

And verified that after post complete, above commands are blocked.

Signed-off-by: Arun Lal K M <arun.lal@intel.com>
Change-Id: Id3a80b91645af72faf3d5715c1e933086b7dd148
diff --git a/src/biosconfigcommands.cpp b/src/biosconfigcommands.cpp
index 3ae4582..c9e9c01 100644
--- a/src/biosconfigcommands.cpp
+++ b/src/biosconfigcommands.cpp
@@ -455,9 +455,13 @@
 /** @brief implement to get the System State
  *  @returns status
  */
-
-static int getSystemOSState(std::string& OsStatus)
+static bool getPostCompleted()
 {
+    /*
+     * In case of failure we treat postCompleted as true.
+     * So that BIOS config commands is not accepted by BMC by mistake.
+     */
+    bool postCompleted = true;
 
     try
     {
@@ -467,13 +471,23 @@
                             "/xyz/openbmc_project/state/os",
                             "xyz.openbmc_project.State.OperatingSystem.Status",
                             "OperatingSystemState");
-        OsStatus = std::get<std::string>(variant);
-        return ipmi::ccSuccess;
+        auto& value = std::get<std::string>(variant);
+
+        // The short strings "Standby" is deprecated in favor of the
+        // full enum strings. Support for the short strings will be
+        // removed in the future.
+        postCompleted = (value == "Standby") ||
+                        (value == "xyz.openbmc_project.State.OperatingSystem."
+                                  "Status.OSStatus.Standby");
     }
     catch (const std::exception& e)
     {
-        return ipmi::ccUnspecifiedError;
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "'getDbusProperty' failed to read "
+            "xyz.openbmc_project.State.OperatingSystem");
     }
+
+    return postCompleted;
 }
 
 /** @brief implement to get the Rest BIOS property
@@ -668,10 +682,7 @@
                                   uint8_t BIOSCapabilties, uint8_t reserved1,
                                   uint8_t reserved2, uint8_t reserved3)
 {
-    std::string OSState;
-    getSystemOSState(OSState);
-
-    if (OSState != "OperatingState" && IsSystemInterface(ctx))
+    if (!getPostCompleted() && IsSystemInterface(ctx))
     {
         if (reserved1 != 0 || reserved2 != 0 || reserved3 != 0)
         {
@@ -715,6 +726,7 @@
     {
         return ipmi::response(ipmiCCBIOSCapabilityInitNotDone);
     }
+
     // Validate the Payload Type
     if (payloadType > maxPayloadSupported)
     {
@@ -724,10 +736,7 @@
     // We should support this Payload type 0 command only in KCS Interface
     if (payloadType == static_cast<uint8_t>(ipmi::PType::IntelXMLType0))
     {
-        std::string OSState;
-
-        getSystemOSState(OSState);
-        if (!IsSystemInterface(ctx) || OSState == "OperatingState")
+        if (!IsSystemInterface(ctx) || getPostCompleted())
         {
             return ipmi::responseCommandNotAvailable();
         }
@@ -1091,19 +1100,15 @@
     ipmi::Context::ptr ctx, std::array<uint8_t, maxSeedSize>& pwdSeed,
     uint8_t algoInfo, std::array<uint8_t, maxHashSize>& adminPwdHash)
 {
-
-    std::string OSState;
-
     // We should support this command only in KCS Interface
     if (!IsSystemInterface(ctx))
     {
         return ipmi::responseCommandNotAvailable();
     }
-    getSystemOSState(OSState);
+
     // We should not support this command after System Booted - After Exit Boot
     // service called
-
-    if (OSState == "OperatingState")
+    if (getPostCompleted())
     {
         return ipmi::response(ipmiCCNotSupportedInCurrentState);
     }
@@ -1146,8 +1151,6 @@
               std::array<uint8_t, maxHashSize>>
     ipmiOEMGetBIOSHash(ipmi::Context::ptr ctx)
 {
-
-    std::string OSState;
     nlohmann::json data = nullptr;
 
     // We should support this command only in KCS Interface
@@ -1156,11 +1159,9 @@
         return ipmi::responseCommandNotAvailable();
     }
 
-    getSystemOSState(OSState);
     // We should not support this command after System Booted - After Exit Boot
     // service called
-
-    if (OSState != "OperatingState")
+    if (!getPostCompleted())
     {
         std::string HashFilePath = "/var/lib/bios-settings-manager/seedData";
 
@@ -1217,7 +1218,6 @@
     }
     else
     {
-
         return ipmi::response(ipmiCCNotSupportedInCurrentState);
     }
 }