oem-ibm: Implement SetEffecter actions corresponding to code
update actions

This commit defines the actions taken corresponding to the code
update actions.

Code update actions include- START, END, ABORT, ACCEPT and REJECT

Signed-off-by: Sagar Srinivas <sagar.srinivas@ibm.com>
Change-Id: I2e86177efe4c8924069cc400b79e4fc4b8983df4
diff --git a/oem/ibm/libpldmresponder/inband_code_update.cpp b/oem/ibm/libpldmresponder/inband_code_update.cpp
index 7055c46..bb06882 100644
--- a/oem/ibm/libpldmresponder/inband_code_update.cpp
+++ b/oem/ibm/libpldmresponder/inband_code_update.cpp
@@ -13,7 +13,6 @@
 
 #include <exception>
 #include <fstream>
-
 namespace pldm
 {
 namespace responder
@@ -96,6 +95,53 @@
     return PLDM_SUCCESS;
 }
 
+int CodeUpdate::setRequestedApplyTime()
+{
+    int rc = PLDM_SUCCESS;
+    pldm::utils::PropertyValue value =
+        "xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.OnReset";
+    DBusMapping dbusMapping;
+    dbusMapping.objectPath = "/xyz/openbmc_project/software/apply_time";
+    dbusMapping.interface = "xyz.openbmc_project.Software.ApplyTime";
+    dbusMapping.propertyName = "RequestedApplyTime";
+    dbusMapping.propertyType = "string";
+    try
+    {
+        pldm::utils::DBusHandler().setDbusProperty(dbusMapping, value);
+    }
+    catch (const std::exception& e)
+    {
+        std::cerr << "Failed To set RequestedApplyTime property "
+                  << "ERROR=" << e.what() << std::endl;
+        rc = PLDM_ERROR;
+    }
+    return rc;
+}
+
+int CodeUpdate::setRequestedActivation()
+{
+    int rc = PLDM_SUCCESS;
+    pldm::utils::PropertyValue value =
+        "xyz.openbmc_project.Software.Activation.RequestedActivations.Active";
+    DBusMapping dbusMapping;
+    dbusMapping.objectPath = newImageId;
+    dbusMapping.interface = "xyz.openbmc_project.Software.Activation";
+    dbusMapping.propertyName = "RequestedActivation";
+    dbusMapping.propertyType = "string";
+    try
+    {
+        pldm::utils::DBusHandler().setDbusProperty(dbusMapping, value);
+    }
+    catch (const std::exception& e)
+    {
+        std::cerr << "Failed To set RequestedActivation property"
+                  << "ERROR=" << e.what() << std::endl;
+        rc = PLDM_ERROR;
+    }
+    newImageId.clear();
+    return rc;
+}
+
 void CodeUpdate::setVersions()
 {
     static constexpr auto mapperService = "xyz.openbmc_project.ObjectMapper";
diff --git a/oem/ibm/libpldmresponder/inband_code_update.hpp b/oem/ibm/libpldmresponder/inband_code_update.hpp
index 28c7c9c..77ada56 100644
--- a/oem/ibm/libpldmresponder/inband_code_update.hpp
+++ b/oem/ibm/libpldmresponder/inband_code_update.hpp
@@ -101,6 +101,20 @@
      */
     void clearDirPath(const std::string& dirPath);
 
+    /* @brief Method to set the RequestApplyTime D-Bus property
+     *        on start update to OnReset
+     * @return - Completion codes
+     */
+    int setRequestedApplyTime();
+
+    /* @brief Method to set the RequestedActivation D-Bus property
+     *        on end update to Active by fetching the newImageID and
+     *        clearning it once RequestedActivation is set or on error
+     * @param[in] codeUpdate - codeUpdate pointer
+     * @return - Completion codes
+     */
+    int setRequestedActivation();
+
     virtual ~CodeUpdate()
     {}
 
diff --git a/oem/ibm/libpldmresponder/oem_ibm_handler.cpp b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
index 53c1bfc..1c6b3fd 100644
--- a/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
+++ b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
@@ -3,8 +3,9 @@
 #include "libpldm/entity.h"
 #include "libpldm/requester/pldm.h"
 
+#include "file_io_type_lid.hpp"
+#include "libpldmresponder/file_io.hpp"
 #include "libpldmresponder/pdr_utils.hpp"
-
 namespace pldm
 {
 namespace responder
@@ -58,6 +59,37 @@
                 rc = setBootSide(entityInstance, currState, stateField,
                                  codeUpdate);
             }
+            else if (entityType == PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE &&
+                     stateSetId == PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE)
+            {
+                if (stateField[currState].effecter_state ==
+                    uint8_t(CodeUpdateState::START))
+                {
+                    codeUpdate->setCodeUpdateProgress(true);
+                    rc = codeUpdate->setRequestedApplyTime();
+                }
+                else if (stateField[currState].effecter_state ==
+                         uint8_t(CodeUpdateState::END))
+                {
+                    codeUpdate->setCodeUpdateProgress(false);
+                }
+                else if (stateField[currState].effecter_state ==
+                         uint8_t(CodeUpdateState::ABORT))
+                {
+                    codeUpdate->setCodeUpdateProgress(false);
+                    codeUpdate->clearDirPath(LID_STAGING_DIR);
+                }
+                else if (stateField[currState].effecter_state ==
+                         uint8_t(CodeUpdateState::ACCEPT))
+                {
+                    // TODO Set new Dbus property provided by code update app
+                }
+                else if (stateField[currState].effecter_state ==
+                         uint8_t(CodeUpdateState::REJECT))
+                {
+                    // TODO Set new Dbus property provided by code update app
+                }
+            }
             else
             {
                 rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE;
diff --git a/oem/ibm/libpldmresponder/oem_ibm_handler.hpp b/oem/ibm/libpldmresponder/oem_ibm_handler.hpp
index bacc3f0..17ad008 100644
--- a/oem/ibm/libpldmresponder/oem_ibm_handler.hpp
+++ b/oem/ibm/libpldmresponder/oem_ibm_handler.hpp
@@ -1,5 +1,4 @@
 #pragma once
-
 #include "libpldm/platform.h"
 
 #include "inband_code_update.hpp"