Support inband write for PELS from HB to bmc

also do not delete the temporary file after calling
DBus api storePel. The file will be deleted by pel daemon
after processing

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I2d38fc42a2d7127eff22983ca83091d323736e2c
diff --git a/oem/ibm/libpldmresponder/file_io_type_pel.cpp b/oem/ibm/libpldmresponder/file_io_type_pel.cpp
index 9197749..00b8e99 100644
--- a/oem/ibm/libpldmresponder/file_io_type_pel.cpp
+++ b/oem/ibm/libpldmresponder/file_io_type_pel.cpp
@@ -209,7 +209,6 @@
     {
         rc = storePel(path.string());
     }
-    fs::remove(path);
     return rc;
 }
 
@@ -271,5 +270,59 @@
     return PLDM_SUCCESS;
 }
 
+int PelHandler::write(const char* buffer, uint32_t offset, uint32_t& length,
+                      oem_platform::Handler* /*oemPlatformHandler*/)
+{
+    int rc = PLDM_SUCCESS;
+
+    if (offset > 0)
+    {
+        std::cerr << "Offset is non zero \n";
+        return PLDM_ERROR;
+    }
+
+    char tmpFile[] = "/tmp/pel.XXXXXX";
+    auto fd = mkstemp(tmpFile);
+    if (fd == -1)
+    {
+        std::cerr << "failed to create a temporary pel, ERROR=" << errno
+                  << "\n";
+        return PLDM_ERROR;
+    }
+
+    size_t written = 0;
+    do
+    {
+        if ((rc = ::write(fd, buffer, length - written)) == -1)
+        {
+            break;
+        }
+        written += rc;
+        buffer += rc;
+    } while (rc && written < length);
+    close(fd);
+
+    if (rc == -1)
+    {
+        std::cerr << "file write failed, ERROR=" << errno
+                  << ", LENGTH=" << length << ", OFFSET=" << offset << "\n";
+        fs::remove(tmpFile);
+        return PLDM_ERROR;
+    }
+
+    if (written == length)
+    {
+        fs::path path(tmpFile);
+        rc = storePel(path.string());
+        if (rc != PLDM_SUCCESS)
+        {
+            std::cerr << "save PEL failed, ERROR = " << rc
+                      << "tmpFile = " << tmpFile << "\n";
+        }
+    }
+
+    return rc;
+}
+
 } // namespace responder
 } // namespace pldm
diff --git a/oem/ibm/libpldmresponder/file_io_type_pel.hpp b/oem/ibm/libpldmresponder/file_io_type_pel.hpp
index fb01b3e..d495185 100644
--- a/oem/ibm/libpldmresponder/file_io_type_pel.hpp
+++ b/oem/ibm/libpldmresponder/file_io_type_pel.hpp
@@ -35,10 +35,7 @@
 
     virtual int write(const char* /*buffer*/, uint32_t /*offset*/,
                       uint32_t& /*length*/,
-                      oem_platform::Handler* /*oemPlatformHandler*/)
-    {
-        return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
-    }
+                      oem_platform::Handler* /*oemPlatformHandler*/);
 
     virtual int fileAck(uint8_t fileStatus);