Implement the PLDM Daemon.

The pldm daemon is a PLDM responder.

PLDM messages received by the PLDM daemon from the MCTP daemon are routed
to the respective command handler to create a response. This response will
be sent back by the PLDM daemon to the requester.

PLDM daemon and MCTP daemon interact with each other using UNIX domain sockets,
as documented in https://github.com/openbmc/docs/blob/master/designs/mctp.md

Implemented a way for the PLDM responder library to register handlers for
specific PLDM commands. This is as per the registration scheme
documented in README.md.

Support for enabling verbosity in the PLDM Daemon (tracing the receive and
response message packets) are conditionally compiled.You would need to
provide the --enable-verbose flag to configure to enable it.

We discard response messages received currently.

Fixed Handler function signature for bios and file_io types.

Tested :

Updated system with the Daemon and did a 'obmcutil poweron'
The Daemon was build with the verbose enabled configuration
Could boot a hypervisor that sends PLDM commands.

Below is the transactions recorded in the journal
Jun 25 13:35:27 witherspoon-128 pldmd[1980]: Received Msg
Jun 25 13:35:27 witherspoon-128 pldmd[1980]: Buffer Data: 09 01 81 3f 06 00
 00 00 00 00 00 00 00 00 00 08 00 00 00 01 00 00 00 00 00
Jun 25 13:35:27 witherspoon-128 pldmd[1980]: Sending Msg
Jun 25 13:35:27 witherspoon-128 pldmd[1980]: Buffer Data: 09 01 00 3f 06 80
 00 00 00 00

Change-Id: I22cfd85103bce167239219fbcc59c25b09528211
Signed-off-by: Jinu Joy Thomas <jinu.joy.thomas@in.ibm.com>
diff --git a/libpldmresponder/base.cpp b/libpldmresponder/base.cpp
index 48ccd54..682b1a7 100644
--- a/libpldmresponder/base.cpp
+++ b/libpldmresponder/base.cpp
@@ -1,6 +1,7 @@
 #include "libpldm/base.h"
 
 #include "base.hpp"
+#include "registration.hpp"
 
 #include <array>
 #include <cstring>
@@ -24,6 +25,20 @@
     {PLDM_BIOS, {0xF1, 0xF0, 0xF0, 0x00}},
 };
 
+namespace base
+{
+
+void registerHandlers()
+{
+    registerHandler(PLDM_BASE, PLDM_GET_PLDM_TYPES, std::move(getPLDMTypes));
+    registerHandler(PLDM_BASE, PLDM_GET_PLDM_COMMANDS,
+                    std::move(getPLDMCommands));
+    registerHandler(PLDM_BASE, PLDM_GET_PLDM_VERSION,
+                    std::move(getPLDMVersion));
+}
+
+} // namespace base
+
 Response getPLDMTypes(const pldm_msg* request, size_t payloadLength)
 {
     // DSP0240 has this as a bitfield8[N], where N = 0 to 7
diff --git a/libpldmresponder/base.hpp b/libpldmresponder/base.hpp
index 466559a..c4afa18 100644
--- a/libpldmresponder/base.hpp
+++ b/libpldmresponder/base.hpp
@@ -16,6 +16,13 @@
 namespace responder
 {
 
+namespace base
+{
+/** @brief Register handlers for command from the base spec
+ */
+void registerHandlers();
+} // namespace base
+
 /** @brief Handler for getPLDMTypes
  *
  *  @param[in] request - Request message payload
diff --git a/libpldmresponder/bios.cpp b/libpldmresponder/bios.cpp
index 11c8251..51d5415 100644
--- a/libpldmresponder/bios.cpp
+++ b/libpldmresponder/bios.cpp
@@ -1,6 +1,7 @@
 #include "bios.hpp"
 
 #include "libpldmresponder/utils.hpp"
+#include "registration.hpp"
 #include "xyz/openbmc_project/Common/error.hpp"
 
 #include <array>
@@ -25,6 +26,16 @@
 namespace responder
 {
 
+namespace bios
+{
+
+void registerHandlers()
+{
+    registerHandler(PLDM_BIOS, PLDM_GET_DATE_TIME, std::move(getDateTime));
+}
+
+} // namespace bios
+
 namespace utils
 {
 
@@ -47,7 +58,7 @@
 
 } // namespace utils
 
-Response getDateTime(const pldm_msg* request)
+Response getDateTime(const pldm_msg* request, size_t payloadLength)
 {
     uint8_t seconds = 0;
     uint8_t minutes = 0;
diff --git a/libpldmresponder/bios.hpp b/libpldmresponder/bios.hpp
index 915a367..2befe24 100644
--- a/libpldmresponder/bios.hpp
+++ b/libpldmresponder/bios.hpp
@@ -14,12 +14,19 @@
 namespace responder
 {
 
+namespace bios
+{
+/** @brief Register handlers for command from the platform spec
+ */
+void registerHandlers();
+} // namespace bios
+
 /** @brief Handler for GetDateTime
  *
  *  @param[in] request - Request message payload
  *  @param[return] Response - PLDM Response message
  */
-Response getDateTime(const pldm_msg* request);
+Response getDateTime(const pldm_msg* request, size_t payloadLength);
 
 namespace utils
 {
diff --git a/libpldmresponder/utils.hpp b/libpldmresponder/utils.hpp
index d76b716..39c7ed6 100644
--- a/libpldmresponder/utils.hpp
+++ b/libpldmresponder/utils.hpp
@@ -2,6 +2,7 @@
 
 #include <stdint.h>
 #include <systemd/sd-bus.h>
+#include <unistd.h>
 
 #include <sdbusplus/server.hpp>
 #include <string>
@@ -10,6 +11,42 @@
 {
 namespace responder
 {
+namespace utils
+{
+
+/** @struct CustomFD
+ *
+ *  RAII wrapper for file descriptor.
+ */
+struct CustomFD
+{
+    CustomFD(const CustomFD&) = delete;
+    CustomFD& operator=(const CustomFD&) = delete;
+    CustomFD(CustomFD&&) = delete;
+    CustomFD& operator=(CustomFD&&) = delete;
+
+    CustomFD(int fd) : fd(fd)
+    {
+    }
+
+    ~CustomFD()
+    {
+        if (fd >= 0)
+        {
+            close(fd);
+        }
+    }
+
+    int operator()() const
+    {
+        return fd;
+    }
+
+  private:
+    int fd = -1;
+};
+
+} // namespace utils
 
 /**
  *  @brief Get the DBUS Service name for the input dbus path