oemcommands: move OEM set fan config to new API

Rewrite "OEM set Fan Config" command to
use the newly introduced IPMI provider API.

Tested:
verified using ipmitool OEM set fan config command

Command: ipmitool raw 0x30 0x89 0x20 0x24
Response:
Command: ipmitool raw 0x30 0x89 0x20 0xc0 //Acoustic mode
Response:                                 //Success
Command: ipmitool raw 0x30 0x89 0x20 0xc4 //Performance mode
Response:                                 //Success

Change-Id: I6875e914f636a0048ff456589d303c7b1c709cac
Signed-off-by: anil kumar appana <anil.kumarx.appana@intel.com>
Signed-off-by: jayaprakash Mutyala <mutyalax.jayaprakash@intel.com>
diff --git a/src/oemcommands.cpp b/src/oemcommands.cpp
index 6cc951e..521c454 100644
--- a/src/oemcommands.cpp
+++ b/src/oemcommands.cpp
@@ -1366,45 +1366,45 @@
     return true;
 }
 
-ipmi_ret_t ipmiOEMSetFanConfig(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
-                               ipmi_request_t request, ipmi_response_t response,
-                               ipmi_data_len_t dataLen, ipmi_context_t context)
+/**@brief implements the OEM set fan config.
+ * @param selectedFanProfile - fan profile to enable
+ * @param reserved1
+ * @param performanceMode - Performance/Acoustic mode
+ * @param reserved2
+ * @param setPerformanceMode - set Performance/Acoustic mode
+ * @param setFanProfile - set fan profile
+ *
+ * @return IPMI completion code.
+ **/
+ipmi::RspType<> ipmiOEMSetFanConfig(uint8_t selectedFanProfile,
+
+                                    uint2_t reserved1, bool performanceMode,
+                                    uint3_t reserved2, bool setPerformanceMode,
+                                    bool setFanProfile)
 {
-
-    if (*dataLen < 2 || *dataLen > 7)
+    if (reserved1 || reserved2)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "ipmiOEMSetFanConfig: invalid input len!");
-        *dataLen = 0;
-        return IPMI_CC_REQ_DATA_LEN_INVALID;
+        return ipmi::responseInvalidFieldRequest();
     }
-
     // todo: tell bios to only send first 2 bytes
-
-    SetFanConfigReq* req = reinterpret_cast<SetFanConfigReq*>(request);
     boost::container::flat_map<
         std::string, std::variant<std::vector<std::string>, std::string>>
         profileData;
     std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
     if (!getFanProfileInterface(*dbus, profileData))
     {
-        return IPMI_CC_UNSPECIFIED_ERROR;
+        return ipmi::responseUnspecifiedError();
     }
 
     std::vector<std::string>* supported =
         std::get_if<std::vector<std::string>>(&profileData["Supported"]);
     if (supported == nullptr)
     {
-        return IPMI_CC_INVALID_FIELD_REQUEST;
+        return ipmi::responseInvalidFieldRequest();
     }
     std::string mode;
-    if (req->flags &
-        (1 << static_cast<uint8_t>(setFanProfileFlags::setPerfAcousMode)))
+    if (setPerformanceMode)
     {
-        bool performanceMode =
-            (req->flags & (1 << static_cast<uint8_t>(
-                               setFanProfileFlags::performAcousSelect))) > 0;
-
         if (performanceMode)
         {
 
@@ -1416,7 +1416,6 @@
         }
         else
         {
-
             if (std::find(supported->begin(), supported->end(), "Acoustic") !=
                 supported->end())
             {
@@ -1425,13 +1424,24 @@
         }
         if (mode.empty())
         {
-            return IPMI_CC_INVALID_FIELD_REQUEST;
+            return ipmi::responseInvalidFieldRequest();
         }
-        setDbusProperty(*dbus, settingsBusName, thermalModePath,
-                        thermalModeInterface, "Current", mode);
+
+        try
+        {
+            setDbusProperty(*dbus, settingsBusName, thermalModePath,
+                            thermalModeInterface, "Current", mode);
+        }
+        catch (sdbusplus::exception_t& e)
+        {
+            phosphor::logging::log<phosphor::logging::level::ERR>(
+                "ipmiOEMSetFanConfig: can't set thermal mode!",
+                phosphor::logging::entry("EXCEPTION=%s", e.what()));
+            return ipmi::responseResponseError();
+        }
     }
 
-    return IPMI_CC_OK;
+    return ipmi::responseSuccess();
 }
 
 ipmi::RspType<uint8_t, // profile support map
@@ -3438,8 +3448,9 @@
                          intel::general::cmdGetShutdownPolicy, NULL,
                          ipmiOEMGetShutdownPolicy, PRIVILEGE_ADMIN);
 
-    ipmiPrintAndRegister(intel::netFnGeneral, intel::general::cmdSetFanConfig,
-                         NULL, ipmiOEMSetFanConfig, PRIVILEGE_USER);
+    registerHandler(prioOemBase, intel::netFnGeneral,
+                    intel::general::cmdSetFanConfig, Privilege::User,
+                    ipmiOEMSetFanConfig);
 
     registerHandler(prioOemBase, intel::netFnGeneral,
                     intel::general::cmdGetFanConfig, Privilege::User,