Implement FRURecordTableMetadata and FRURecordTable command

This commit implements the GetFRURecordTableMetadata and GetFRURecordTable
in the PLDM specification DSP0257 for FRU data specification. The FRU table
is populated by the FRU handler class with the configs from the path
/usr/share/pldm/fru.

Tested:

On a Witherspoon system the Get FRURecordTableMetadata and FRURecordTable
command were executed and ensured the FRU table in the command response
matches with the D-Bus inventory properties.

Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Change-Id: I16d36df2834b65bfa5f69164d3a40eeac2c7f357
diff --git a/libpldmresponder/fru.cpp b/libpldmresponder/fru.cpp
index 096c4f7..01afde3 100644
--- a/libpldmresponder/fru.cpp
+++ b/libpldmresponder/fru.cpp
@@ -172,6 +172,60 @@
                 iter);
 }
 
+namespace fru
+{
+
+Response Handler::getFRURecordTableMetadata(const pldm_msg* request,
+                                            size_t /*payloadLength*/)
+{
+    constexpr uint8_t major = 0x01;
+    constexpr uint8_t minor = 0x00;
+    constexpr uint32_t maxSize = 0xFFFFFFFF;
+
+    Response response(sizeof(pldm_msg_hdr) +
+                          PLDM_GET_FRU_RECORD_TABLE_METADATA_RESP_BYTES,
+                      0);
+    auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
+
+    auto rc = encode_get_fru_record_table_metadata_resp(
+        request->hdr.instance_id, PLDM_SUCCESS, major, minor, maxSize,
+        impl.size(), impl.numRSI(), impl.numRecords(), impl.checkSum(),
+        responsePtr);
+    if (rc != PLDM_SUCCESS)
+    {
+        return ccOnlyResponse(request, rc);
+    }
+
+    return response;
+}
+
+Response Handler::getFRURecordTable(const pldm_msg* request,
+                                    size_t payloadLength)
+{
+    if (payloadLength != PLDM_GET_FRU_RECORD_TABLE_REQ_BYTES)
+    {
+        return ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
+    }
+
+    Response response(
+        sizeof(pldm_msg_hdr) + PLDM_GET_FRU_RECORD_TABLE_MIN_RESP_BYTES, 0);
+    auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
+
+    auto rc =
+        encode_get_fru_record_table_resp(request->hdr.instance_id, PLDM_SUCCESS,
+                                         0, PLDM_START_AND_END, responsePtr);
+    if (rc != PLDM_SUCCESS)
+    {
+        return ccOnlyResponse(request, rc);
+    }
+
+    impl.getFRUTable(response);
+
+    return response;
+}
+
+} // namespace fru
+
 } // namespace responder
 
 } // namespace pldm