oem-ibm: Resource dump support

This commit includes the changes to support resource dump. Input
parameters to initiate resource dump are vsp string and the
password.

Resource Dump Flow:
1. PLDM waits for the resource dump create signal from
   dump manager
2. BMC sends the NewfileAvailable command to hypervisor with
   resource dump paramters
   Format: <Length of the VSP String><VSP String>
   <Length of the Password><Password>
3. Hypervisor reads and validates the data and send the File Ack
   command back to BMC
4. Once completed, BMC receives the NewfileAvailable command from
   hypervisor with resource dump details
5. User initiates the dump offload
6. BMC receives the  write file by type from memory command from
   hypervisor
7. Once this operation is completed BMC receives the File Ack
   command from hyperviosr

Tested By:
1. Initiating the resource dump using pldmtool, busctl and redfish
2. Verified that resource dump entry is updated with source id,
   length, completion time and status.
3. Dump offload is successful with initiating from redfish
4. Verified that new resource dump is generated at hypervisor level
5. Error scenarios tested are like empty vsp string, not supported
   vsp string etc.

Signed-off-by: Jayashankar Padath <jayashankar.padath@in.ibm.com>
Change-Id: Iedcdf3cf16c263a2d1749bb5251f7f6244c327ea
diff --git a/oem/ibm/libpldmresponder/file_io.hpp b/oem/ibm/libpldmresponder/file_io.hpp
index 9f6492c..a79c677 100644
--- a/oem/ibm/libpldmresponder/file_io.hpp
+++ b/oem/ibm/libpldmresponder/file_io.hpp
@@ -7,6 +7,7 @@
 #include "oem/ibm/libpldm/host.h"
 
 #include "common/utils.hpp"
+#include "oem/ibm/requester/dbus_to_file_handler.hpp"
 #include "oem_ibm_handler.hpp"
 #include "pldmd/handler.hpp"
 
@@ -155,11 +156,16 @@
 
 namespace oem_ibm
 {
+static constexpr auto dumpObjPath = "/xyz/openbmc_project/dump/resource/entry/";
+static constexpr auto resDumpEntry = "com.ibm.Dump.Entry.Resource";
 class Handler : public CmdHandler
 {
   public:
-    Handler(oem_platform::Handler* oemPlatformHandler) :
-        oemPlatformHandler(oemPlatformHandler)
+    Handler(oem_platform::Handler* oemPlatformHandler, int hostSockFd,
+            uint8_t hostEid, dbus_api::Requester* dbusImplReqester) :
+        oemPlatformHandler(oemPlatformHandler),
+        hostSockFd(hostSockFd), hostEid(hostEid),
+        dbusImplReqester(dbusImplReqester)
     {
         handlers.emplace(PLDM_READ_FILE_INTO_MEMORY,
                          [this](const pldm_msg* request, size_t payloadLength) {
@@ -216,6 +222,48 @@
                              return this->newFileAvailable(request,
                                                            payloadLength);
                          });
+
+        resDumpMatcher = std::make_unique<sdbusplus::bus::match::match>(
+            pldm::utils::DBusHandler::getBus(),
+            sdbusplus::bus::match::rules::interfacesAdded() +
+                sdbusplus::bus::match::rules::argNpath(0, dumpObjPath),
+            [hostSockFd, hostEid,
+             dbusImplReqester](sdbusplus::message::message& msg) {
+                std::map<
+                    std::string,
+                    std::map<std::string, std::variant<std::string, uint32_t>>>
+                    interfaces;
+                sdbusplus::message::object_path path;
+                msg.read(path, interfaces);
+                std::string vspstring;
+                std::string password;
+
+                for (auto& interface : interfaces)
+                {
+                    if (interface.first == resDumpEntry)
+                    {
+                        for (const auto& property : interface.second)
+                        {
+                            if (property.first == "VSPString")
+                            {
+                                vspstring =
+                                    std::get<std::string>(property.second);
+                            }
+                            else if (property.first == "Password")
+                            {
+                                password =
+                                    std::get<std::string>(property.second);
+                            }
+                        }
+                        auto dbusToFileHandler = std::make_unique<
+                            pldm::requester::oem_ibm::DbusToFileHandler>(
+                            hostSockFd, hostEid, dbusImplReqester, path);
+                        dbusToFileHandler->processNewResourceDump(vspstring,
+                                                                  password);
+                        break;
+                    }
+                }
+            });
     }
 
     /** @brief Handler for readFileIntoMemory command
@@ -317,6 +365,15 @@
 
   private:
     oem_platform::Handler* oemPlatformHandler;
+    int hostSockFd;
+    uint8_t hostEid;
+    dbus_api::Requester* dbusImplReqester;
+    using DBusInterfaceAdded = std::vector<std::pair<
+        std::string,
+        std::vector<std::pair<std::string, std::variant<std::string>>>>>;
+    std::unique_ptr<sdbusplus::bus::match::match>
+        resDumpMatcher; //!< Pointer to capture the interface added signal
+                        //!< for new resource dump
 };
 
 } // namespace oem_ibm