oem ibm: infrastructure for oem handlers

1. This commit adds the framework for an oem handler
which can be used by specific oem use-cases
for implementing various commands.

2. This commit adds implementation for getStateSensorReadings
and setStateEffecterStates commands for oem state sets.

3. Also adds implementation for inband code update.

Change-Id: Ib38a66ee381dd06b93f6a9313d51de1c23e6ee65
Signed-off-by: Sampa Misra <sampmisr@in.ibm.com>
diff --git a/oem/ibm/libpldmresponder/file_io.hpp b/oem/ibm/libpldmresponder/file_io.hpp
index 771d038..9f6492c 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_handler.hpp"
 #include "pldmd/handler.hpp"
 
 #include <fcntl.h>
@@ -157,7 +158,8 @@
 class Handler : public CmdHandler
 {
   public:
-    Handler()
+    Handler(oem_platform::Handler* oemPlatformHandler) :
+        oemPlatformHandler(oemPlatformHandler)
     {
         handlers.emplace(PLDM_READ_FILE_INTO_MEMORY,
                          [this](const pldm_msg* request, size_t payloadLength) {
@@ -312,6 +314,9 @@
      *  @return PLDM response message
      */
     Response newFileAvailable(const pldm_msg* request, size_t payloadLength);
+
+  private:
+    oem_platform::Handler* oemPlatformHandler;
 };
 
 } // namespace oem_ibm
diff --git a/oem/ibm/libpldmresponder/inband_code_update.cpp b/oem/ibm/libpldmresponder/inband_code_update.cpp
new file mode 100644
index 0000000..f17b209
--- /dev/null
+++ b/oem/ibm/libpldmresponder/inband_code_update.cpp
@@ -0,0 +1,217 @@
+#include "inband_code_update.hpp"
+
+#include "oem_ibm_handler.hpp"
+#include "xyz/openbmc_project/Common/error.hpp"
+
+#include <sdbusplus/server.hpp>
+#include <xyz/openbmc_project/Dump/NewDump/server.hpp>
+
+#include <exception>
+
+namespace pldm
+{
+
+namespace responder
+{
+using namespace oem_ibm_platform;
+
+std::string CodeUpdate::fetchCurrentBootSide()
+{
+    return currBootSide;
+}
+
+std::string CodeUpdate::fetchNextBootSide()
+{
+    return nextBootSide;
+}
+
+int CodeUpdate::setCurrentBootSide(const std::string& currSide)
+{
+    currBootSide = currSide;
+    return PLDM_SUCCESS;
+}
+
+int CodeUpdate::setNextBootSide(const std::string& nextSide)
+{
+    nextBootSide = nextSide;
+    std::string objPath{};
+    if (nextBootSide == currBootSide)
+    {
+        objPath = runningVersion;
+    }
+    else
+    {
+        objPath = nonRunningVersion;
+    }
+    if (objPath.empty())
+    {
+        std::cerr << "no nonRunningVersion present \n";
+        return PLDM_PLATFORM_INVALID_STATE_VALUE;
+    }
+
+    pldm::utils::DBusMapping dbusMapping{objPath, redundancyIntf, "Priority",
+                                         "uint8_t"};
+    uint8_t val = 0;
+    pldm::utils::PropertyValue value = static_cast<uint8_t>(val);
+    try
+    {
+        dBusIntf->setDbusProperty(dbusMapping, value);
+    }
+    catch (const std::exception& e)
+    {
+        std::cerr << "failed to set the next boot side to " << objPath.c_str()
+                  << " ERROR=" << e.what() << "\n";
+        return PLDM_ERROR;
+    }
+    return PLDM_SUCCESS;
+}
+
+void CodeUpdate::setVersions()
+{
+    static constexpr auto mapperService = "xyz.openbmc_project.ObjectMapper";
+    static constexpr auto functionalObjPath =
+        "/xyz/openbmc_project/software/functional";
+    static constexpr auto activeObjPath =
+        "/xyz/openbmc_project/software/active";
+    static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
+
+    auto& bus = dBusIntf->getBus();
+
+    try
+    {
+        auto method = bus.new_method_call(mapperService, functionalObjPath,
+                                          propIntf, "Get");
+        method.append("xyz.openbmc_project.Association", "endpoints");
+        std::variant<std::vector<std::string>> paths;
+
+        auto reply = bus.call(method);
+        reply.read(paths);
+
+        runningVersion = std::get<std::vector<std::string>>(paths)[0];
+
+        auto method1 =
+            bus.new_method_call(mapperService, activeObjPath, propIntf, "Get");
+        method1.append("xyz.openbmc_project.Association", "endpoints");
+
+        auto reply1 = bus.call(method1);
+        reply1.read(paths);
+        for (const auto& path : std::get<std::vector<std::string>>(paths))
+        {
+            if (path != runningVersion)
+            {
+                nonRunningVersion = path;
+                break;
+            }
+        }
+    }
+    catch (const std::exception& e)
+    {
+        std::cerr << "failed to make a d-bus call to Object Mapper "
+                     "Association, ERROR="
+                  << e.what() << "\n";
+        return;
+    }
+
+    using namespace sdbusplus::bus::match::rules;
+    captureNextBootSideChange.push_back(
+        std::make_unique<sdbusplus::bus::match::match>(
+            pldm::utils::DBusHandler::getBus(),
+            propertiesChanged(runningVersion, redundancyIntf),
+            [this](sdbusplus::message::message& msg) {
+                DbusChangedProps props;
+                std::string iface;
+                msg.read(iface, props);
+                processPriorityChangeNotification(props);
+            }));
+    fwUpdateMatcher = std::make_unique<sdbusplus::bus::match::match>(
+        pldm::utils::DBusHandler::getBus(),
+        "interface='org.freedesktop.DBus.ObjectManager',type='signal',"
+        "member='InterfacesAdded',path='/xyz/openbmc_project/software'",
+        [this](sdbusplus::message::message& msg) {
+            DBusInterfaceAdded interfaces;
+            sdbusplus::message::object_path path;
+            msg.read(path, interfaces);
+            for (auto& interface : interfaces)
+            {
+                if (interface.first ==
+                    "xyz.openbmc_project.Software.Activation")
+                {
+                    newImageId = path.str;
+                    break;
+                }
+            }
+        });
+}
+
+void CodeUpdate::processPriorityChangeNotification(
+    const DbusChangedProps& chProperties)
+{
+    static constexpr auto propName = "Priority";
+    const auto it = chProperties.find(propName);
+    if (it == chProperties.end())
+    {
+        return;
+    }
+    uint8_t newVal = std::get<uint8_t>(it->second);
+    nextBootSide = (newVal == 0) ? currBootSide
+                                 : ((currBootSide == Tside) ? Pside : Tside);
+}
+
+void CodeUpdate::setOemPlatformHandler(
+    pldm::responder::oem_platform::Handler* handler)
+{
+    oemPlatformHandler = handler;
+}
+
+uint8_t fetchBootSide(uint16_t entityInstance, CodeUpdate* codeUpdate)
+{
+    uint8_t sensorOpState = tSideNum;
+
+    if (entityInstance == 0)
+    {
+        auto currSide = codeUpdate->fetchCurrentBootSide();
+        if (currSide == Pside)
+        {
+            sensorOpState = pSideNum;
+        }
+    }
+    else if (entityInstance == 1)
+    {
+        auto nextSide = codeUpdate->fetchNextBootSide();
+        if (nextSide == Pside)
+        {
+            sensorOpState = pSideNum;
+        }
+    }
+    else
+    {
+        sensorOpState = PLDM_SENSOR_UNKNOWN;
+    }
+
+    return sensorOpState;
+}
+
+int setBootSide(uint16_t entityInstance, uint8_t currState,
+                const std::vector<set_effecter_state_field>& stateField,
+                CodeUpdate* codeUpdate)
+{
+    int rc = PLDM_SUCCESS;
+    auto side = (stateField[currState].effecter_state == pSideNum) ? "P" : "T";
+
+    if (entityInstance == 0)
+    {
+        rc = codeUpdate->setCurrentBootSide(side);
+    }
+    else if (entityInstance == 1)
+    {
+        rc = codeUpdate->setNextBootSide(side);
+    }
+    else
+    {
+        rc = PLDM_PLATFORM_INVALID_STATE_VALUE;
+    }
+    return rc;
+}
+
+} // namespace responder
+} // namespace pldm
diff --git a/oem/ibm/libpldmresponder/inband_code_update.hpp b/oem/ibm/libpldmresponder/inband_code_update.hpp
new file mode 100644
index 0000000..6607de0
--- /dev/null
+++ b/oem/ibm/libpldmresponder/inband_code_update.hpp
@@ -0,0 +1,128 @@
+#pragma once
+
+#include "common/utils.hpp"
+#include "libpldmresponder/platform.hpp"
+
+#include <string>
+
+using namespace pldm::utils;
+namespace pldm
+{
+namespace responder
+{
+
+static constexpr uint8_t pSideNum = 1;
+static constexpr uint8_t tSideNum = 2;
+static constexpr auto Pside = "P";
+static constexpr auto Tside = "T";
+
+static constexpr auto redundancyIntf =
+    "xyz.openbmc_project.Software.RedundancyPriority";
+
+/** @class CodeUpdate
+ *
+ *  @brief This class performs the necessary operation in pldm for
+ *         inband code update. That includes taking actions on the
+ *         setStateEffecterStates calls from Host and also sending
+ *         notification to phosphor-software-manager app
+ */
+class CodeUpdate
+{
+  public:
+    /** @brief Constructor to create an inband codeupdate object
+     *  @param[in] dBusIntf - D-Bus handler pointer
+     */
+    CodeUpdate(const pldm::utils::DBusHandler* dBusIntf) : dBusIntf(dBusIntf)
+    {
+        currBootSide = Tside;
+        nextBootSide = Tside;
+    }
+
+    /* @brief Method to return the current boot side
+     */
+    std::string fetchCurrentBootSide();
+
+    /* @brief Method to return the next boot side
+     */
+    std::string fetchNextBootSide();
+
+    /* @brief Method to set the current boot side or
+     *        perform a rename operation on current boot side
+     * @param[in] currSide - current side to be set to
+     * @return PLDM_SUCCESS codes
+     */
+    int setCurrentBootSide(const std::string& currSide);
+
+    /* @brief Method to set the next boot side
+     * @param[in] nextSide - next boot side to be set to
+     * @return PLDM_SUCCESS codes
+     */
+    int setNextBootSide(const std::string& nextSide);
+
+    /* @brief Method to set the running and non-running
+     *        images
+     */
+    virtual void setVersions();
+
+    /* @brief Method to return the newly upoaded image id in
+     *        /tmp
+     */
+    std::string fetchnewImageId()
+    {
+        return newImageId;
+    }
+
+    /* @brief Method to set the oem platform handler in CodeUpdate class */
+    void setOemPlatformHandler(pldm::responder::oem_platform::Handler* handler);
+
+    virtual ~CodeUpdate()
+    {}
+
+  private:
+    std::string currBootSide;      //!< current boot side
+    std::string nextBootSide;      //!< next boot side
+    std::string runningVersion;    //!< currently running image
+    std::string nonRunningVersion; //!< alternate image
+    std::string newImageId;        //!< new image id
+    bool codeUpdateInProgress =
+        false; //!< indicates whether codeupdate is going on
+    const pldm::utils::DBusHandler* dBusIntf; //!< D-Bus handler
+    std::vector<std::unique_ptr<sdbusplus::bus::match::match>>
+        captureNextBootSideChange; //!< vector to catch the D-Bus property
+                                   //!< change for next boot side
+    std::unique_ptr<sdbusplus::bus::match::match>
+        fwUpdateMatcher; //!< pointer to capture the interface added signal for
+                         //!< new image
+    pldm::responder::oem_platform::Handler*
+        oemPlatformHandler; //!< oem platform handler
+
+    /* @brief Method to take action when the subscribed D-Bus property is
+     *        changed
+     * @param[in] chProperties - list of properties which have changed
+     * @return - none
+     */
+
+    void
+        processPriorityChangeNotification(const DbusChangedProps& chProperties);
+};
+
+/* @brief Method to fetch current or next boot side
+ * @param[in] entityInstance - entity instance for the sensor
+ * @param[in] codeUpdate - pointer to the CodeUpdate object
+ *
+ * @return - boot side
+ */
+uint8_t fetchBootSide(uint16_t entityInstance, CodeUpdate* codeUpdate);
+
+/* @brief Method to set current or next  boot side
+ * @param[in] entityInstance - entity instance for the effecter
+ * @param[in] currState - state to be set
+ * @param[in] stateField - state field set as sent by Host
+ * @return - PLDM_SUCCESS codes
+ */
+int setBootSide(uint16_t entityInstance, uint8_t currState,
+                const std::vector<set_effecter_state_field>& stateField,
+                CodeUpdate* codeUpdate);
+
+} // namespace responder
+} // namespace pldm
diff --git a/oem/ibm/libpldmresponder/oem_ibm_handler.cpp b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
new file mode 100644
index 0000000..2e6bd4c
--- /dev/null
+++ b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
@@ -0,0 +1,83 @@
+#include "oem_ibm_handler.hpp"
+
+#include "libpldm/entity.h"
+
+namespace pldm
+{
+
+namespace responder
+{
+
+namespace oem_ibm_platform
+{
+
+int pldm::responder::oem_ibm_platform::Handler::
+    getOemStateSensorReadingsHandler(
+        EntityType entityType, EntityInstance entityInstance,
+        StateSetId stateSetId, CompositeCount compSensorCnt,
+        std::vector<get_sensor_state_field>& stateField)
+{
+    int rc = PLDM_SUCCESS;
+    stateField.clear();
+
+    for (size_t i = 0; i < compSensorCnt; i++)
+    {
+        uint8_t sensorOpState{};
+        if (entityType == PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER &&
+            stateSetId == PLDM_OEM_IBM_BOOT_STATE)
+        {
+            sensorOpState = fetchBootSide(entityInstance, codeUpdate);
+        }
+        else
+        {
+            rc = PLDM_PLATFORM_INVALID_STATE_VALUE;
+            break;
+        }
+        stateField.push_back({PLDM_SENSOR_ENABLED, PLDM_SENSOR_UNKNOWN,
+                              PLDM_SENSOR_UNKNOWN, sensorOpState});
+    }
+    return rc;
+}
+
+int pldm::responder::oem_ibm_platform::Handler::
+    oemSetStateEffecterStatesHandler(
+        EntityType entityType, EntityInstance entityInstance,
+        StateSetId stateSetId, CompositeCount compEffecterCnt,
+        const std::vector<set_effecter_state_field>& stateField)
+{
+    int rc = PLDM_SUCCESS;
+
+    for (uint8_t currState = 0; currState < compEffecterCnt; ++currState)
+    {
+        if (stateField[currState].set_request == PLDM_REQUEST_SET)
+        {
+            if (entityType == PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER &&
+                stateSetId == PLDM_OEM_IBM_BOOT_STATE)
+            {
+                rc = setBootSide(entityInstance, currState, stateField,
+                                 codeUpdate);
+            }
+            else
+            {
+                rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE;
+            }
+        }
+        if (rc != PLDM_SUCCESS)
+        {
+            break;
+        }
+    }
+    return rc;
+}
+
+void pldm::responder::oem_ibm_platform::Handler::setPlatformHandler(
+    pldm::responder::platform::Handler* handler)
+{
+    platformHandler = handler;
+}
+
+} // namespace oem_ibm_platform
+
+} // namespace responder
+
+} // namespace pldm
diff --git a/oem/ibm/libpldmresponder/oem_ibm_handler.hpp b/oem/ibm/libpldmresponder/oem_ibm_handler.hpp
new file mode 100644
index 0000000..2d294f0
--- /dev/null
+++ b/oem/ibm/libpldmresponder/oem_ibm_handler.hpp
@@ -0,0 +1,57 @@
+#pragma once
+
+#include "inband_code_update.hpp"
+#include "libpldmresponder/oem_handler.hpp"
+#include "libpldmresponder/platform.hpp"
+
+namespace pldm
+{
+
+namespace responder
+{
+
+namespace oem_ibm_platform
+{
+
+#define PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE 32768
+#define PLDM_OEM_IBM_BOOT_STATE 32769
+
+class Handler : public oem_platform::Handler
+{
+  public:
+    Handler(const pldm::utils::DBusHandler* dBusIntf,
+            pldm::responder::CodeUpdate* codeUpdate) :
+        oem_platform::Handler(dBusIntf),
+        codeUpdate(codeUpdate), platformHandler(nullptr)
+    {
+        codeUpdate->setVersions();
+    }
+
+    int getOemStateSensorReadingsHandler(
+        EntityType entityType, EntityInstance entityInstance,
+        StateSetId stateSetId, CompositeCount compSensorCnt,
+        std::vector<get_sensor_state_field>& stateField);
+
+    int oemSetStateEffecterStatesHandler(
+        EntityType entityType, EntityInstance entityInstance,
+        StateSetId stateSetId, CompositeCount compEffecterCnt,
+        const std::vector<set_effecter_state_field>& stateField);
+
+    /** @brief Method to set the platform handler in the
+     *         oem_ibm_handler class
+     *  @param[in] handler - pointer to PLDM platform handler
+     */
+    void setPlatformHandler(pldm::responder::platform::Handler* handler);
+
+    ~Handler() = default;
+
+    pldm::responder::CodeUpdate* codeUpdate; //!< pointer to CodeUpdate object
+    pldm::responder::platform::Handler*
+        platformHandler; //!< pointer to PLDM platform handler
+};
+
+} // namespace oem_ibm_platform
+
+} // namespace responder
+
+} // namespace pldm
diff --git a/oem/ibm/test/libpldmresponder_fileio_test.cpp b/oem/ibm/test/libpldmresponder_fileio_test.cpp
index e425a9a..65998a7 100644
--- a/oem/ibm/test/libpldmresponder_fileio_test.cpp
+++ b/oem/ibm/test/libpldmresponder_fileio_test.cpp
@@ -222,7 +222,8 @@
            &address, sizeof(address));
 
     // Pass invalid payload length
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto response = handler.readFileIntoMemory(request, 0);
     auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
     ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR_INVALID_LENGTH);
@@ -252,7 +253,8 @@
     // Initialise the file table with 2 valid file handles 0 & 1.
     auto& table = buildFileTable(fileTableConfig.c_str());
 
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto response = handler.readFileIntoMemory(request, requestPayloadLength);
     auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
     ASSERT_EQ(responsePtr->payload[0], PLDM_INVALID_FILE_HANDLE);
@@ -283,7 +285,8 @@
     using namespace pldm::filetable;
     auto& table = buildFileTable(fileTableConfig.c_str());
 
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto response = handler.readFileIntoMemory(request, requestPayloadLength);
     auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
     ASSERT_EQ(responsePtr->payload[0], PLDM_DATA_OUT_OF_RANGE);
@@ -314,7 +317,8 @@
     using namespace pldm::filetable;
     auto& table = buildFileTable(fileTableConfig.c_str());
 
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto response = handler.readFileIntoMemory(request, requestPayloadLength);
     auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
     ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR_INVALID_LENGTH);
@@ -348,7 +352,8 @@
     using namespace pldm::filetable;
     auto& table = buildFileTable(fileTableConfig.c_str());
 
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto response = handler.readFileIntoMemory(request, requestPayloadLength);
     auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
     ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR_INVALID_LENGTH);
@@ -376,7 +381,8 @@
            &address, sizeof(address));
 
     // Pass invalid payload length
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto response = handler.writeFileFromMemory(request, 0);
     auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
     ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR_INVALID_LENGTH);
@@ -411,7 +417,8 @@
     // Initialise the file table with 2 valid file handles 0 & 1.
     auto& table = buildFileTable(fileTableConfig.c_str());
 
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto response = handler.writeFileFromMemory(request, requestPayloadLength);
     auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
     ASSERT_EQ(responsePtr->payload[0], PLDM_INVALID_FILE_HANDLE);
@@ -443,7 +450,8 @@
     // Initialise the file table with 2 valid file handles 0 & 1.
     auto& table = buildFileTable(TestFileTable::fileTableConfig.c_str());
 
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto response = handler.writeFileFromMemory(request, requestPayloadLength);
     auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
     ASSERT_EQ(responsePtr->payload[0], PLDM_DATA_OUT_OF_RANGE);
@@ -512,7 +520,8 @@
     request->operation_flag = opFlag;
     request->table_type = type;
 
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto response = handler.getFileTable(requestMsgPtr, requestPayloadLength);
     auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
     ASSERT_EQ(responsePtr->payload[0], PLDM_SUCCESS);
@@ -535,7 +544,8 @@
     auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
 
     // Pass invalid command payload length
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto response = handler.getFileTable(request, 0);
     auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
     ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR_INVALID_LENGTH);
@@ -557,7 +567,8 @@
     request->operation_flag = opFlag;
     request->table_type = type;
 
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto response = handler.getFileTable(requestMsgPtr, requestPayloadLength);
     auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
     ASSERT_EQ(responsePtr->payload[0], PLDM_INVALID_FILE_TABLE_TYPE);
@@ -585,7 +596,8 @@
     auto& table = buildFileTable(fileTableConfig.c_str());
 
     // Invalid payload length
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto response = handler.readFile(requestMsgPtr, 0);
     auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
     ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR_INVALID_LENGTH);
@@ -635,7 +647,8 @@
     std::vector<char> buffer(length);
     stream.read(buffer.data(), length);
 
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto responseMsg = handler.readFile(requestMsgPtr, payload_length);
     auto response = reinterpret_cast<pldm_read_file_resp*>(
         responseMsg.data() + sizeof(pldm_msg_hdr));
@@ -685,7 +698,8 @@
     request->length = length;
 
     // Invalid payload length
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto response = handler.writeFile(requestMsgPtr, 0);
     auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
     ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR_INVALID_LENGTH);
@@ -732,7 +746,8 @@
     request->length = length;
     memcpy(request->file_data, fileData.data(), fileData.size());
 
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto responseMsg = handler.writeFile(requestMsgPtr, payload_length);
     auto response = reinterpret_cast<pldm_read_file_resp*>(
         responseMsg.data() + sizeof(pldm_msg_hdr));
@@ -765,7 +780,8 @@
     request->length = 17;
     request->address = 0;
 
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto response = handler.writeFileByTypeFromMemory(req, 0);
     auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
 
@@ -833,7 +849,8 @@
     request->length = 17;
     request->address = 0;
 
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto response = handler.readFileByTypeIntoMemory(req, 0);
     auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
     struct pldm_read_write_file_by_type_memory_resp* resp =
@@ -871,7 +888,8 @@
     request->offset = 0;
     request->length = 13;
 
-    oem_ibm::Handler handler;
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+    oem_ibm::Handler handler(oemPlatformHandler.get());
     auto response = handler.readFileByType(req, 0);
     auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
     struct pldm_read_write_file_by_type_resp* resp =
diff --git a/oem/ibm/test/libpldmresponder_oem_platform_test.cpp b/oem/ibm/test/libpldmresponder_oem_platform_test.cpp
new file mode 100644
index 0000000..6b837dd
--- /dev/null
+++ b/oem/ibm/test/libpldmresponder_oem_platform_test.cpp
@@ -0,0 +1,103 @@
+#include "libpldm/entity.h"
+
+#include "common/utils.hpp"
+#include "libpldmresponder/event_parser.hpp"
+#include "libpldmresponder/pdr.hpp"
+#include "libpldmresponder/pdr_utils.hpp"
+#include "libpldmresponder/platform.hpp"
+#include "oem/ibm/libpldmresponder/inband_code_update.hpp"
+#include "oem/ibm/libpldmresponder/oem_ibm_handler.hpp"
+#include "test/mocked_utils.hpp"
+
+#include <iostream>
+
+using namespace pldm::utils;
+using namespace pldm::responder;
+using namespace pldm::responder::pdr;
+using namespace pldm::responder::pdr_utils;
+using namespace pldm::responder::oem_ibm_platform;
+
+class MockCodeUpdate : public CodeUpdate
+{
+  public:
+    MockCodeUpdate(const pldm::utils::DBusHandler* dBusIntf) :
+        CodeUpdate(dBusIntf)
+    {}
+
+    MOCK_METHOD(void, setVersions, (), (override));
+};
+
+TEST(oemSetStateEffecterStatesHandler, testGoodRequest)
+{
+    uint16_t entityID_ = PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER;
+    uint16_t stateSetId_ = PLDM_OEM_IBM_BOOT_STATE;
+    uint16_t entityInstance_ = 0;
+    uint8_t compSensorCnt_ = 1;
+
+    std::vector<get_sensor_state_field> stateField;
+
+    auto mockDbusHandler = std::make_unique<MockdBusHandler>();
+    std::unique_ptr<CodeUpdate> mockCodeUpdate =
+        std::make_unique<MockCodeUpdate>(mockDbusHandler.get());
+    std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
+
+    oemPlatformHandler = std::make_unique<oem_ibm_platform::Handler>(
+        mockDbusHandler.get(), mockCodeUpdate.get());
+
+    auto rc = oemPlatformHandler->getOemStateSensorReadingsHandler(
+        entityID_, entityInstance_, stateSetId_, compSensorCnt_, stateField);
+
+    ASSERT_EQ(rc, PLDM_SUCCESS);
+    ASSERT_EQ(stateField.size(), 1);
+    ASSERT_EQ(stateField[0].event_state, tSideNum);
+    ASSERT_EQ(stateField[0].sensor_op_state, PLDM_SENSOR_ENABLED);
+    ASSERT_EQ(stateField[0].present_state, PLDM_SENSOR_UNKNOWN);
+    ASSERT_EQ(stateField[0].previous_state, PLDM_SENSOR_UNKNOWN);
+
+    entityInstance_ = 1;
+
+    std::vector<get_sensor_state_field> stateField1;
+    rc = oemPlatformHandler->getOemStateSensorReadingsHandler(
+        entityID_, entityInstance_, stateSetId_, compSensorCnt_, stateField1);
+    ASSERT_EQ(stateField1.size(), 1);
+    ASSERT_EQ(stateField1[0].event_state, tSideNum);
+
+    entityInstance_ = 2;
+    rc = oemPlatformHandler->getOemStateSensorReadingsHandler(
+        entityID_, entityInstance_, stateSetId_, compSensorCnt_, stateField1);
+    ASSERT_EQ(stateField1[0].event_state, PLDM_SENSOR_UNKNOWN);
+
+    entityID_ = 40;
+    stateSetId_ = 50;
+    rc = oemPlatformHandler->getOemStateSensorReadingsHandler(
+        entityID_, entityInstance_, stateSetId_, compSensorCnt_, stateField1);
+    ASSERT_EQ(rc, PLDM_PLATFORM_INVALID_STATE_VALUE);
+
+    entityID_ = PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER;
+    entityInstance_ = 0;
+    stateSetId_ = PLDM_OEM_IBM_BOOT_STATE;
+    compSensorCnt_ = 1;
+
+    std::vector<set_effecter_state_field> setEffecterStateField;
+    setEffecterStateField.push_back({PLDM_REQUEST_SET, pSideNum});
+
+    rc = oemPlatformHandler->oemSetStateEffecterStatesHandler(
+        entityID_, entityInstance_, stateSetId_, compSensorCnt_,
+        setEffecterStateField);
+    ASSERT_EQ(rc, PLDM_SUCCESS);
+
+    entityInstance_ = 2;
+    rc = oemPlatformHandler->oemSetStateEffecterStatesHandler(
+        entityID_, entityInstance_, stateSetId_, compSensorCnt_,
+        setEffecterStateField);
+
+    ASSERT_EQ(rc, PLDM_PLATFORM_INVALID_STATE_VALUE);
+
+    entityID_ = 34;
+    stateSetId_ = 99;
+    entityInstance_ = 0;
+    rc = oemPlatformHandler->oemSetStateEffecterStatesHandler(
+        entityID_, entityInstance_, stateSetId_, compSensorCnt_,
+        setEffecterStateField);
+    ASSERT_EQ(rc, PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE);
+}