Fix SMMDR send directory info call

Call to send directory method fails to give data if it sends input
below 32 bytes, which as per spec should be allowed considering
N*16 bytes. Hence changing the condition.
Also, it wasn't working for more than 1 directory , so made changes
accordingly.

Tested:
Checked via dbus method-call and IPMI OEM commands, it works fine.

busctl call xyz.openbmc_project.Smbios.MDR_V2 /xyz/openbmc_project/Smbios/MDR_V2
xyz.openbmc_project.Smbios.MDR_V2 SendDirectoryInformation yyyyay
2 0 2 0 32 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 66
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 76
b true

busctl call xyz.openbmc_project.Smbios.MDR_V2 /xyz/openbmc_project/Smbios/MDR_V2
xyz.openbmc_project.Smbios.MDR_V2 GetDirectoryInformation y 0
ay 36 2 2 2 0 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 66
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 76

SmmdrSendDirectoryInfo(38h) executes successfully with correct input
and fails with request data length invalid in case of incorrect input.

ipmitool raw 0x3E 0x38 0x1 0x1 0x1 0x0 0x1 0x0 0x28 0x29 0x2a 0x2b 0x2c
0x2d 0x2e 0x2f 0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x42
 01         // SUCCESS

ipmitool raw 0x3E 0x38 0x1 0x1 0x1 0x0 0x1 0x0 0x28 0x29 0x2a 0x2b 0x2c
0x2d 0x2e 0x2f 0x30 0x31 0x32
Unable to send RAW command (channel=0x0 netfn=0x3e lun=0x0 cmd=0x38
rsp=0xc7): Request data length invalid

Signed-off-by: Mansi Joshi <mansi.joshi@linux.intel.com>
Change-Id: Ia07df1f9ad502308181a791f6afc2554f6d8a6fc
diff --git a/src/mdrv2.cpp b/src/mdrv2.cpp
index 00fbdcc..1d173c4 100644
--- a/src/mdrv2.cpp
+++ b/src/mdrv2.cpp
@@ -256,7 +256,8 @@
         throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
             InvalidParameter();
     }
-    if (dirEntry.size() < sizeof(Mdr2DirEntry))
+    if ((static_cast<size_t>(returnedEntries) * sizeof(DataIdStruct)) !=
+        dirEntry.size())
     {
         phosphor::logging::log<phosphor::logging::level::ERR>(
             "Directory size invalid");
@@ -279,6 +280,7 @@
             smbiosDir.dirVersion = dirVersion;
         }
         uint8_t idIndex = dirIndex;
+        smbiosDir.dirEntries = returnedEntries;
 
         uint8_t* pData = dirEntry.data();
         if (pData == nullptr)
@@ -287,15 +289,10 @@
         }
         for (uint8_t index = 0; index < returnedEntries; index++)
         {
-            auto data = reinterpret_cast<const Mdr2DirEntry*>(pData);
-            smbiosDir.dir[idIndex + index].common.dataVersion =
-                data->dataVersion;
-            std::copy(data->id.dataInfo,
-                      data->id.dataInfo + sizeof(DataIdStruct),
+            auto data = reinterpret_cast<const DataIdStruct*>(pData);
+            std::copy(data->dataInfo, data->dataInfo + sizeof(DataIdStruct),
                       smbiosDir.dir[idIndex + index].common.id.dataInfo);
-            smbiosDir.dir[idIndex + index].common.dataSetSize = data->size;
-            smbiosDir.dir[idIndex + index].common.timestamp = data->timestamp;
-            pData += sizeof(returnedEntries);
+            pData += sizeof(DataIdStruct);
         }
     }
     return teminate;