PFR: PFR manager ad-hoc fixes

PFR manager miscellaneous fixes
 - Updated redfish EventLog ID and Args.
 - Updated panic/recovery reasons as per new spec.
 - Corrected referrence pointer in readCpldReg function.

Tested:
Loaded image in wht and validate Redfish event logs

Change-Id: I4bccbfe650271bcfcc24037c50d385c5fa17dbf1
Signed-off-by: AppaRao Puli <apparao.puli@linux.intel.com>
diff --git a/libpfr/inc/pfr.hpp b/libpfr/inc/pfr.hpp
index cd1b4f2..42af3f7 100644
--- a/libpfr/inc/pfr.hpp
+++ b/libpfr/inc/pfr.hpp
@@ -41,9 +41,10 @@
     minorError
 };
 
+std::string toHexString(const uint8_t val);
 std::string getVersionInfoCPLD(ImageType &imgType);
 int getProvisioningStatus(bool &ufmLocked, bool &ufmProvisioned);
-int readCpldReg(const ActionType &action, uint8_t value);
+int readCpldReg(const ActionType &action, uint8_t &value);
 int setBMCBootCheckpoint(const uint8_t checkPoint);
 
 } // namespace pfr
diff --git a/libpfr/src/pfr.cpp b/libpfr/src/pfr.cpp
index c30ef5b..955b6d7 100644
--- a/libpfr/src/pfr.cpp
+++ b/libpfr/src/pfr.cpp
@@ -54,11 +54,11 @@
 static constexpr uint8_t ufmLockedMask = (0x1 << 0x04);
 static constexpr uint8_t ufmProvisionedMask = (0x1 << 0x05);
 
-template <typename T> std::string int_to_hexstring(T i)
+std::string toHexString(const uint8_t val)
 {
     std::stringstream stream;
-    stream << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex
-           << static_cast<int>(i);
+    stream << std::setfill('0') << std::setw(2) << std::hex
+           << static_cast<int>(val);
     return stream.str();
 }
 
@@ -110,7 +110,7 @@
         uint8_t majorVer = cpldDev.i2cReadByteData(majorReg);
         uint8_t minorVer = cpldDev.i2cReadByteData(minorReg);
         std::string version =
-            int_to_hexstring(majorVer) + "." + int_to_hexstring(minorVer);
+            toHexString(majorVer) + "." + toHexString(minorVer);
         return version;
     }
     catch (const std::exception& e)
@@ -141,7 +141,7 @@
     }
 }
 
-int readCpldReg(const ActionType& action, uint8_t value)
+int readCpldReg(const ActionType& action, uint8_t& value)
 {
     uint8_t cpldReg;
 
diff --git a/service/src/mainapp.cpp b/service/src/mainapp.cpp
index 103ab22..ae92f65 100644
--- a/service/src/mainapp.cpp
+++ b/service/src/mainapp.cpp
@@ -56,33 +56,32 @@
 static std::map<uint8_t, std::string> recoveryReasonMap = {
     {0x01, "PCH active authentication failure"},
     {0x02, "PCH recovery authentication failure"},
-    {0x03, "ACM launch failure"},
-    {0x04, "IBB launch failure"},
-    {0x05, "OBB launch failure"},
-    {0x06, "BMC active authentication failure"},
-    {0x07, "BMC recovery authentication failure"},
-    {0x08, "BMC launch failure"},
-    {0x09, "CPLD watchdog expired"}};
+    {0x03, "ME launch failure"},
+    {0x04, "ACM launch failure"},
+    {0x05, "IBB launch failure"},
+    {0x06, "OBB launch failure"},
+    {0x07, "BMC active authentication failure"},
+    {0x08, "BMC recovery authentication failure"},
+    {0x09, "BMC launch failure"},
+    {0x0A, "CPLD watchdog expired"}};
 
 // Panic Reason map. { <CPLD association>, <Panic reason> }
 static std::map<uint8_t, std::string> panicReasonMap = {
-    {0x01, "CPLD WDT expired"},
-    {0x02, "BMC WDT expired"},
-    {0x03, "ME WDT expired"},
-    {0x04, "ACM WDT expired"},
-    {0x05, "IBB WDT expired"},
-    {0x06, "OBB WDT expired"},
+    {0x01, "CPLD watchdog expired"},
+    {0x02, "BMC watchdog expired"},
+    {0x03, "ME watchdog expired"},
+    {0x04, "ACM watchdog expired"},
+    {0x05, "IBB watchdog expired"},
+    {0x06, "OBB watchdog expired"},
     {0x07, "BMC active authentication failure"},
     {0x08, "BMC recovery authentication failure"},
     {0x09, "PCH active authentication failure"},
     {0x0A, "PCH recovery authentication failure"},
-    {0x0B, "IBB authentication failure"},
-    {0x0C, "OBB authentication failure"},
-    {0x0D, "BMC authentication failure"},
-    {0x0E, "PCH active update intent"},
-    {0x0F, "BMC active update intent"},
-    {0x10, "PCH recovery update intent"},
-    {0x11, "BMC recovery update intent"}};
+    {0x0B, "ME authentication failure"},
+    {0x0C, "ACM or IBB or OBB authentication failure"},
+    {0x0D, "PCH update intent"},
+    {0x0E, "BMC update intent"},
+    {0x0F, "BMC reset detected"}};
 
 static void updateDbusPropertiesCache()
 {
@@ -115,10 +114,10 @@
         return;
     }
 
-    sd_journal_send("MESSAGE=%s", "Platform firmware recovered.", "PRIORITY=%i",
-                    LOG_ERR, "REDFISH_MESSAGE_ID=%s",
-                    "OpenBMC.0.1.PlatformFWRecovered",
-                    "REDFISH_MESSAGE_ARGS=%s", it->second.c_str(), NULL);
+    sd_journal_send(
+        "MESSAGE=%s", "Platform firmware recovered.", "PRIORITY=%i", LOG_ERR,
+        "REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.PlatformFirmwareEvent",
+        "REDFISH_MESSAGE_ARGS=%s,%s", "recovery", it->second.c_str(), NULL);
 }
 
 static void logLastPanicEvent()
@@ -138,10 +137,10 @@
         return;
     }
 
-    sd_journal_send("MESSAGE=%s", "Platform panic event triggered.",
-                    "PRIORITY=%i", LOG_ERR, "REDFISH_MESSAGE_ID=%s",
-                    "OpenBMC.0.1.PlatformFWPanicTriggered",
-                    "REDFISH_MESSAGE_ARGS=%s", it->second.c_str(), NULL);
+    sd_journal_send(
+        "MESSAGE=%s", "Platform panic event triggered.", "PRIORITY=%i", LOG_ERR,
+        "REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.PlatformFirmwareEvent",
+        "REDFISH_MESSAGE_ARGS=%s,%s", "panic", it->second.c_str(), NULL);
 }
 
 static void checkAndLogEvents()
@@ -184,11 +183,13 @@
 
             if (majorErr || minorErr)
             {
-                sd_journal_send(
-                    "MESSAGE=%s", "Error occurred on platform firmware.",
-                    "PRIORITY=%i", LOG_ERR, "REDFISH_MESSAGE_ID=%s",
-                    "OpenBMC.0.1.PlatformFWErrorOccurred",
-                    "REDFISH_MESSAGE_ARGS=%i,%i", majorErr, minorErr, NULL);
+                std::string errorStr =
+                    toHexString(majorErr) + "." + toHexString(minorErr);
+                sd_journal_send("MESSAGE=%s",
+                                "Error occurred on platform firmware.",
+                                "PRIORITY=%i", LOG_ERR, "REDFISH_MESSAGE_ID=%s",
+                                "OpenBMC.0.1.PlatformFirmwareError",
+                                "REDFISH_MESSAGE_ARGS=%s", errorStr, NULL);
             }
         }
     }