PEL: Write terminating SRC to the progress SRC

Check for incoming pels for severity type 0x51 - Critical error,
System termination. If found, fetch the SRC and add this SRC to
progress SRC interface on dbus. In addition set the terminate bit
in BMC created pels only.

Signed-off-by: Sumit Kumar <sumit_kumar@in.ibm.com>
Change-Id: I26194a26743263183dcb61e097c745c4705fa006
diff --git a/extensions/openpower-pels/manager.cpp b/extensions/openpower-pels/manager.cpp
index 95c53ca..331238e 100644
--- a/extensions/openpower-pels/manager.cpp
+++ b/extensions/openpower-pels/manager.cpp
@@ -163,6 +163,9 @@
         // Update System Info to Extended User Data
         pel->updateSysInfoInExtendedUserDataSection(*_dataIface);
 
+        // Check for severity 0x51 and update boot progress SRC
+        updateProgressSRC(pel);
+
         try
         {
             log<level::DEBUG>(
@@ -385,6 +388,9 @@
         log<level::INFO>(msg.c_str());
     }
 
+    // Check for severity 0x51 and update boot progress SRC
+    updateProgressSRC(pel);
+
     // Activate any resulting service indicators if necessary
     auto policy = service_indicators::getPolicy(*_dataIface);
     policy->activate(*pel);
@@ -860,5 +866,37 @@
     }
 }
 
+void Manager::updateProgressSRC(
+    std::unique_ptr<openpower::pels::PEL>& pel) const
+{
+    // Check for pel severity of type - 0x51 = critical error, system
+    // termination
+    if (pel->userHeader().severity() == 0x51)
+    {
+        auto src = pel->primarySRC();
+        if (src)
+        {
+            std::vector<uint8_t> asciiSRC = (*src)->getSrcStruct();
+            uint64_t srcRefCode = 0;
+
+            // Read bytes from offset [40-47] e.g. BD8D1001
+            for (int i = 0; i < 8; i++)
+            {
+                srcRefCode |=
+                    (static_cast<uint64_t>(asciiSRC[40 + i]) << (8 * i));
+            }
+
+            try
+            {
+                _dataIface->createProgressSRC(srcRefCode, asciiSRC);
+            }
+            catch (std::exception& e)
+            {
+                // Exception - may be no boot progress interface on dbus
+            }
+        }
+    }
+}
+
 } // namespace pels
 } // namespace openpower