oem-ibm: inband: Check lid is complete

A lid file can be written in one or more write requests. Read
the header for the expected size to check if the lid has been
fully written. The file size should be the lid size listed in
the header minus the size of the header.

Change-Id: I0fa02af3e50f13b40cea2494471445918826d716
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 8de9993..2023a99 100644
--- a/oem/ibm/libpldmresponder/inband_code_update.cpp
+++ b/oem/ibm/libpldmresponder/inband_code_update.cpp
@@ -221,6 +221,14 @@
     struct LidHeader
     {
         uint16_t magicNumber;
+        uint16_t headerVersion;
+        uint32_t lidNumber;
+        uint32_t lidDate;
+        uint16_t lidTime;
+        uint16_t lidClass;
+        uint32_t lidCrc;
+        uint32_t lidSize;
+        uint32_t headerSize;
     };
     LidHeader header;
 
@@ -234,6 +242,15 @@
     ifs.read(reinterpret_cast<char*>(&header), sizeof(header));
     ifs.close();
 
+    // File size should be the value of lid size minus the header size
+    auto fileSize = fs::file_size(filePath);
+    fileSize -= htonl(header.headerSize);
+    if (fileSize < htonl(header.lidSize))
+    {
+        // File is not completely written yet
+        return PLDM_SUCCESS;
+    }
+
     constexpr auto magicNumber = 0x0222;
     if (htons(header.magicNumber) != magicNumber)
     {