PLDM: implement surveillance between Host and bmc

This commit is to implement surveillance between host
and bmc, wherein host monitors if bmc is up and
running through constant pings(by sending Platform
EventMessages) sent from host to BMC. And if BMC
fails to respond to the pings, then BMC will be
reset using the KCS interface.

1. Host->BMC - GetTID
2. BMC->Host - Respond to GetTID, SetEventReceiver
3. Host->BMC - Respond to SetEventReceiver
4. BMC->Host -  Send PlatformEventMessage after the
   elapsed time interval(specified with
   SetEventReceiver command)
4. Host->BMC - If BMC fails to send respond to host
   within specified interval, Host resets BMC via
   the KCS interface

Tested with PLDMTOOL:
SetEventReceiver command:
root@rain127bmc:/tmp# ./pldmtool base GetTID -m 8
Received Msg
08 01 81 00 02
Sending Msg
01 00 02 00 01
{
    "Response": 1
}

platformEventMessage command(which will be received
by host):
root@rain118bmc:/tmp# ./pldmtool raw -d 0x80 0x02
0x0A 0x01 0x01 0x06 0x01 0x01
Request Message:
08 01 80 02 0a 01 01 06 01 01
Received Msg
08 01 80 02 0a 01 01 06 01 01
eventClass Checking
Sending Msg
00 02 0a 00 00
Response Message:
08 01 00 02 0a 00 00
Received Msg
08 01 00 02 0a 00 00

Signed-off-by: Sagar Srinivas <sagar.srinivas@ibm.com>
Change-Id: Iac90b2233a873a54504ffa649d324d30525b7ce3
diff --git a/libpldmresponder/base.hpp b/libpldmresponder/base.hpp
index 6e5b653..195e221 100644
--- a/libpldmresponder/base.hpp
+++ b/libpldmresponder/base.hpp
@@ -1,13 +1,21 @@
 #pragma once
 
 #include "libpldm/base.h"
+#include "libpldm/platform.h"
 
+#include "pldmd/dbus_impl_requester.hpp"
 #include "pldmd/handler.hpp"
+#include "requester/handler.hpp"
 
 #include <stdint.h>
 
+#include <sdeventplus/source/event.hpp>
+
 #include <vector>
 
+using namespace pldm::dbus_api;
+using namespace pldm::responder;
+
 namespace pldm
 {
 namespace responder
@@ -18,7 +26,10 @@
 class Handler : public CmdHandler
 {
   public:
-    Handler()
+    Handler(uint8_t eid, Requester& requester, sdeventplus::Event& event,
+            pldm::requester::Handler<pldm::requester::Request>* handler) :
+        eid(eid),
+        requester(requester), event(event), handler(handler)
     {
         handlers.emplace(PLDM_GET_PLDM_TYPES,
                          [this](const pldm_msg* request, size_t payloadLength) {
@@ -62,6 +73,14 @@
      */
     Response getPLDMVersion(const pldm_msg* request, size_t payloadLength);
 
+    /** @brief _processSetEventReceiver does the actual work that needs
+     *  to be carried out for setEventReceiver command. This is deferred
+     *  after sending response for getTID command to the host
+     *
+     *  @param[in] source - sdeventplus event source
+     */
+    void processSetEventReceiver(sdeventplus::source::EventBase& source);
+
     /** @brief Handler for getTID
      *
      *  @param[in] request - Request message payload
@@ -69,6 +88,26 @@
      *  @param[return] Response - PLDM Response message
      */
     Response getTID(const pldm_msg* request, size_t payloadLength);
+
+  private:
+    /** @brief MCTP EID of host firmware */
+    uint8_t eid;
+
+    /** @brief reference to Requester object, primarily used to access API to
+     *  obtain PLDM instance id.
+     */
+    Requester& requester;
+
+    /** @brief reference of main event loop of pldmd, primarily used to schedule
+     *  work
+     */
+    sdeventplus::Event& event;
+
+    /** @brief PLDM request handler */
+    pldm::requester::Handler<pldm::requester::Request>* handler;
+
+    /** @brief sdeventplus event source */
+    std::unique_ptr<sdeventplus::source::Defer> survEvent;
 };
 
 } // namespace base