smbiosmdrv2handler: move mdr2 lock data to new API.

Rewrite "MDRII_LOCK_DATA" cmd to new IPMI provider API.

Tested:
verified using ipmitool smbiosmdrv2handler commands.
mdr2 lock data before and after the changes.
Command: ipmitool raw 0x3E 0x33 0x01 0x01 40 41 42 43 44 45 46 47 48 49
 50 51 52 53 54 0x42 0x0a 0xa
Output: Unable to send RAW command (channel=0x0 netfn=0x3e lun=0x0 cmd=0x33
rsp=0xd5): Command not supported in present state

Command: ipmitool raw 0x3E 0x33 0x01 0x01 40 41 42 43 44 45 46 47 48 49
 50 51 52 53 50 0x42 1 0xff
Output: Unable to send RAW command (channel=0x0 netfn=0x3e lun=0x0
cmd=0x33 rsp=0xc9): Parameter out of range

Signed-off-by: jayaprakash Mutyala <mutyalax.jayaprakash@intel.com>
Change-Id: Ie0eddd716deeb522da89448bb1977735e87bc08a
diff --git a/src/smbiosmdrv2handler.cpp b/src/smbiosmdrv2handler.cpp
index 2d1c92c..9e5be61 100644
--- a/src/smbiosmdrv2handler.cpp
+++ b/src/smbiosmdrv2handler.cpp
@@ -35,6 +35,7 @@
 
 std::unique_ptr<MDRV2> mdrv2 = nullptr;
 static constexpr const uint8_t ccOemInvalidChecksum = 0x85;
+static constexpr size_t dataInfoSize = 16;
 
 static void register_netfn_smbiosmdrv2_functions() __attribute__((constructor));
 
@@ -1015,68 +1016,66 @@
     mdrv2->area.reset(nullptr);
 }
 
-ipmi_ret_t cmd_mdr2_lock_data(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
-                              ipmi_request_t request, ipmi_response_t response,
-                              ipmi_data_len_t data_len, ipmi_context_t context)
+/** @brief implements mdr2 lock data command
+ *  @param agentId
+ *  @param dataInfo
+ *  @param timeout
+ *
+ *  @returns IPMI completion code plus response data
+ *  - mdr2Version
+ *  - session
+ *  - dataLength
+ *  - xferAddress
+ *  - xferLength
+ */
+ipmi::RspType<uint8_t,  // mdr2Version
+              uint16_t, // session
+              uint32_t, // dataLength
+              uint32_t, // xferAddress
+              uint32_t  // xferLength
+              >
+    mdr2LockData(uint16_t agentId, std::array<uint8_t, dataInfoSize> dataInfo,
+                 uint16_t timeout)
 {
-    auto requestData = reinterpret_cast<const MDRiiLockDataRequest *>(request);
-    auto responseData = reinterpret_cast<MDRiiLockDataResponse *>(response);
-    uint16_t session = 0;
-
-    std::tuple<bool, uint8_t, uint16_t, uint32_t, uint32_t, uint32_t> res;
-
-    if (*data_len < sizeof(MDRiiLockDataRequest))
-    {
-        *data_len = 0;
-        return IPMI_CC_REQ_DATA_LEN_INVALID;
-    }
-
-    *data_len = 0;
-
     if (mdrv2 == nullptr)
     {
         mdrv2 = std::make_unique<MDRV2>();
     }
 
-    int agentIndex = mdrv2->agentLookup(requestData->agentId);
+    int agentIndex = mdrv2->agentLookup(agentId);
     if (agentIndex == -1)
     {
         phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Unknown agent id",
-            phosphor::logging::entry("ID=%x", requestData->agentId));
-        return IPMI_CC_PARM_OUT_OF_RANGE;
+            "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
+        return ipmi::responseParmOutOfRange();
     }
 
     std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
     std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
 
-    int idIndex =
-        mdrv2->findDataId(requestData->dataSetInfo.dataInfo,
-                          sizeof(requestData->dataSetInfo.dataInfo), service);
+    int idIndex = mdrv2->findDataId(dataInfo.data(), sizeof(dataInfo), service);
 
     if ((idIndex < 0) || (idIndex >= maxDirEntries))
     {
         phosphor::logging::log<phosphor::logging::level::ERR>(
             "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex));
-        return IPMI_CC_PARM_OUT_OF_RANGE;
+        return ipmi::responseParmOutOfRange();
     }
 
-    if (!mdrv2->smbiosTryLock(0, idIndex, &session, requestData->timeout))
+    uint16_t session = 0;
+    if (!mdrv2->smbiosTryLock(0, idIndex, &session, timeout))
     {
         phosphor::logging::log<phosphor::logging::level::ERR>(
             "Lock Data failed - cannot lock idIndex");
-        return IPMI_CC_PARAMETER_NOT_SUPPORT_IN_PRESENT_STATE;
+        return ipmi::responseCommandNotAvailable();
     }
 
-    *data_len = sizeof(MDRiiLockDataResponse);
+    uint32_t dataLength = mdrv2->smbiosDir.dir[idIndex].common.size;
+    uint32_t xferAddress = mdrv2->smbiosDir.dir[idIndex].xferBuff;
+    uint32_t xferLength = mdrv2->smbiosDir.dir[idIndex].xferSize;
 
-    responseData->mdrVersion = mdr2Version;
-    responseData->lockHandle = session;
-    responseData->dataLength = mdrv2->smbiosDir.dir[idIndex].common.size;
-    responseData->xferAddress = mdrv2->smbiosDir.dir[idIndex].xferBuff;
-    responseData->xferLength = mdrv2->smbiosDir.dir[idIndex].xferSize;
-
-    return IPMI_CC_OK;
+    return ipmi::responseSuccess(mdr2Version, session, dataLength, xferAddress,
+                                 xferLength);
 }
 
 /** @brief implements mdr2 unlock data command
@@ -1349,9 +1348,9 @@
                           ipmi::Privilege::Operator, mdr2SendDataBlock);
 
     // <Lock MDRII Data Command>
-    ipmi_register_callback(NETFUN_INTEL_APP_OEM,
-                           IPMI_NETFN_INTEL_OEM_APP_CMD::MDRII_LOCK_DATA, NULL,
-                           cmd_mdr2_lock_data, PRIVILEGE_OPERATOR);
+    ipmi::registerHandler(ipmi::prioOemBase, NETFUN_INTEL_APP_OEM,
+                          IPMI_NETFN_INTEL_OEM_APP_CMD::MDRII_LOCK_DATA,
+                          ipmi::Privilege::Operator, mdr2LockData);
 
     // <Unlock MDRII Data Command>
     ipmi::registerHandler(ipmi::prioOemBase, NETFUN_INTEL_APP_OEM,