oem-ibm: inband: Add processCodeUpdateLid()

The new processCodeUpdateLid() function will process the LID
files sent by the hypervisor so that they can be used by the
code update application to be writtent to flash.

This first commit validates that the LID files contain a valid
magic number in their header.

Change-Id: I9113d46fa6af0d0ef8a0c7b898c1229d49ff05e6
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/oem/ibm/libpldmresponder/inband_code_update.cpp b/oem/ibm/libpldmresponder/inband_code_update.cpp
index cdcf143..8de9993 100644
--- a/oem/ibm/libpldmresponder/inband_code_update.cpp
+++ b/oem/ibm/libpldmresponder/inband_code_update.cpp
@@ -6,10 +6,13 @@
 #include "oem_ibm_handler.hpp"
 #include "xyz/openbmc_project/Common/error.hpp"
 
+#include <arpa/inet.h>
+
 #include <sdbusplus/server.hpp>
 #include <xyz/openbmc_project/Dump/NewDump/server.hpp>
 
 #include <exception>
+#include <fstream>
 
 namespace pldm
 {
@@ -213,5 +216,33 @@
     return rc;
 }
 
+int processCodeUpdateLid(const std::string& filePath)
+{
+    struct LidHeader
+    {
+        uint16_t magicNumber;
+    };
+    LidHeader header;
+
+    std::ifstream ifs(filePath, std::ios::in | std::ios::binary);
+    if (!ifs)
+    {
+        std::cerr << "ifstream open error: " << filePath << "\n";
+        return PLDM_ERROR;
+    }
+    ifs.seekg(0);
+    ifs.read(reinterpret_cast<char*>(&header), sizeof(header));
+    ifs.close();
+
+    constexpr auto magicNumber = 0x0222;
+    if (htons(header.magicNumber) != magicNumber)
+    {
+        std::cerr << "Invalid magic number: " << filePath << "\n";
+        return PLDM_ERROR;
+    }
+
+    return PLDM_SUCCESS;
+}
+
 } // namespace responder
 } // namespace pldm