smbiosmdrv2handler: move mdr2 send dir to new API

Rewrite "MDRII_SEND_DIR" command to new IPMI provider API.

Tested:
verified using ipmitool smbiosmdrv2handler commands.
a. mdr2 send dir, before and after the changes.
ipmitool raw 0x3E 0x38 0x01 0x01 0 0 2 3 40 41 42 43 44 45 46 47 48 49
 50 51 52 53 50 0x42 1 1  1 1 0  0 1 1 0 0 0 1 1 0xa  1 1
Output: Unable to send RAW command (channel=0x0 netfn=0x3e lun=0x0
cmd=0x38 rsp=0xce): Command response could not be provided

ipmitool raw 0x3E 0x38 0x01 0x01 0 0 0xff 0xff 40 41 42 43 44 45 46 47
48 49 50 51 52 53 50 0x42 1 1  1 1 0  0 1 1 0 0 0 1 1 0xa  1 1
Output: Unable to send RAW command (channel=0x0 netfn=0x3e lun=0x0
cmd=0x38 rsp=0xc4): Out of space

Signed-off-by: jayaprakash Mutyala <mutyalax.jayaprakash@intel.com>
Change-Id: I5c2ef08965949cffd7863689a0b010928ccfc786
diff --git a/include/smbiosmdrv2handler.hpp b/include/smbiosmdrv2handler.hpp
index 3254f47..8b4b5b7 100644
--- a/include/smbiosmdrv2handler.hpp
+++ b/include/smbiosmdrv2handler.hpp
@@ -173,17 +173,6 @@
 };
 
 // ====================== MDR II Push Command Structures ======================
-// MDR II Push Agent send dir info command
-struct MDRiiSendDirRequest
-{
-    uint16_t agentId;
-    uint8_t dirVersion;
-    uint8_t dirIndex;
-    uint8_t returnedEntries;
-    uint8_t remainingEntries;
-    Mdr2DirEntry data[1]; // place holder for N directory entries
-};
-
 // MDR II Client send data set info offer response
 struct MDRiiOfferDataInfoResponse
 {
diff --git a/src/smbiosmdrv2handler.cpp b/src/smbiosmdrv2handler.cpp
index 9e5be61..5f3dd84 100644
--- a/src/smbiosmdrv2handler.cpp
+++ b/src/smbiosmdrv2handler.cpp
@@ -36,6 +36,7 @@
 std::unique_ptr<MDRV2> mdrv2 = nullptr;
 static constexpr const uint8_t ccOemInvalidChecksum = 0x85;
 static constexpr size_t dataInfoSize = 16;
+static constexpr const uint8_t ccStorageLeak = 0xC4;
 
 static void register_netfn_smbiosmdrv2_functions() __attribute__((constructor));
 
@@ -345,22 +346,13 @@
     return ipmi::responseSuccess(dataOut);
 }
 
-ipmi_ret_t cmd_mdr2_send_dir(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)
+ipmi::RspType<bool> mdr2SendDir(uint16_t agentId, uint8_t dirVersion,
+                                uint8_t dirIndex, uint8_t returnedEntries,
+                                uint8_t remainingEntries,
+                                std::array<uint8_t, 16> dataInfo, uint32_t size,
+                                uint32_t dataSetSize, uint32_t dataVersion,
+                                uint32_t timestamp)
 {
-    auto requestData = reinterpret_cast<const MDRiiSendDirRequest *>(request);
-    std::vector<uint8_t> idVector;
-    bool teminate = false;
-
-    if (*data_len != sizeof(MDRiiSendDirRequest))
-    {
-        *data_len = 0;
-        return IPMI_CC_REQ_DATA_LEN_INVALID;
-    }
-
-    *data_len = 0;
-
     std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
     std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
 
@@ -369,38 +361,31 @@
         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();
     }
 
-    if ((requestData->dirIndex + requestData->returnedEntries) > maxDirEntries)
+    if ((dirIndex + returnedEntries) > maxDirEntries)
     {
         phosphor::logging::log<phosphor::logging::level::ERR>(
             "Too many directory entries");
-        return IPMI_CC_STORGE_LEAK;
+        return ipmi::response(ccStorageLeak);
     }
 
     sdbusplus::message::message method = bus->new_method_call(
         service.c_str(), mdrv2Path, mdrv2Interface, "SendDirectoryInformation");
-    method.append(requestData->dirVersion, requestData->dirIndex,
-                  requestData->returnedEntries, requestData->remainingEntries);
-    uint8_t *reqPoint;
-    for (int index = 0; index < requestData->returnedEntries; index++)
-    {
-        reqPoint = (uint8_t *)&(requestData->data[index]);
-        std::copy(reqPoint, sizeof(Mdr2DirEntry) + reqPoint, idVector.data());
-    }
-    method.append(idVector);
+    method.append(dirVersion, dirIndex, returnedEntries, remainingEntries,
+                  dataInfo, size, dataSetSize, dataVersion, timestamp);
 
+    bool terminate = false;
     try
     {
         sdbusplus::message::message reply = bus->call(method);
-        reply.read(teminate);
+        reply.read(terminate);
     }
     catch (sdbusplus::exception_t &e)
     {
@@ -408,15 +393,10 @@
             "Error send dir", phosphor::logging::entry("ERROR=%s", e.what()),
             phosphor::logging::entry("SERVICE=%s", service.c_str()),
             phosphor::logging::entry("PATH=%s", mdrv2Path));
-        return IPMI_CC_RESPONSE_ERROR;
+        return ipmi::responseResponseError();
     }
 
-    *data_len = 1;
-    if (teminate == false)
-        *(static_cast<uint8_t *>(response)) = 0;
-    else
-        *(static_cast<uint8_t *>(response)) = 1;
-    return IPMI_CC_OK;
+    return ipmi::responseSuccess(terminate);
 }
 
 ipmi_ret_t cmd_mdr2_get_data_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
@@ -1317,9 +1297,9 @@
                           ipmi::Privilege::Operator, mdr2GetDir);
 
     // <Send MDRII Directory Command>
-    ipmi_register_callback(NETFUN_INTEL_APP_OEM,
-                           IPMI_NETFN_INTEL_OEM_APP_CMD::MDRII_SEND_DIR, NULL,
-                           cmd_mdr2_send_dir, PRIVILEGE_OPERATOR);
+    ipmi::registerHandler(ipmi::prioOemBase, NETFUN_INTEL_APP_OEM,
+                          IPMI_NETFN_INTEL_OEM_APP_CMD::MDRII_SEND_DIR,
+                          ipmi::Privilege::Operator, mdr2SendDir);
 
     // <Get MDRII Data Info Command>
     ipmi_register_callback(NETFUN_INTEL_APP_OEM,