platform: encode_get_pdr_repository_info_req() in PLDM platform

Add encode API for GetPDRRepositoryInfo request based on
DSP0248 1.3.0 Section 26.1 Table 68.

Change-Id: I61c3d11c1e15eccfd7f96795e5098b0e0f2d1423
Signed-off-by: Vishnu Santhosh <quic_vishsant@quicinc.com>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 41bafd1..0e093f6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@
 - utils: Introduce `pldm_edac_crc32()`
 - utils: Introduce `pldm_edac_crc8()`
 - pdr: Add pldm_pdr_delete_by_effecter_id() API
+- platform: Add encode req for GetPDRRepositoryInfo
 
 - oem: ibm: Add boot side rename state set and enum
 
diff --git a/include/libpldm/platform.h b/include/libpldm/platform.h
index 888eb76..89af565 100644
--- a/include/libpldm/platform.h
+++ b/include/libpldm/platform.h
@@ -1598,6 +1598,23 @@
 
 /*GetPDRRepositoryInfo*/
 
+/** @brief Encode GetPDRRepositoryInfo request data
+ *
+ *  @param[in] instance_id - Message's instance id
+ *  @param[out] msg - Message will be written to this
+  * @param[in] payload_length - length of request message payload
+ *  @return 0 on success
+ *         -EINVAL if the input parameters' memory are not allocated,
+ *         or message type or instance in request header is invalid
+ *         -ENOMSG if the PLDM type in the request header is invalid
+ *         -EOVERFLOW if the input message length is invalid
+ *  @note  Caller is responsible for memory alloc and dealloc of param
+ *         'msg.payload'
+ */
+int encode_get_pdr_repository_info_req(uint8_t instance_id,
+				       struct pldm_msg *msg,
+				       size_t payload_length);
+
 /** @brief Encode GetPDRRepositoryInfo response data
  *
  *  @param[in] instance_id - Message's instance id
diff --git a/src/dsp/platform.c b/src/dsp/platform.c
index 18de641..7ad8e2f 100644
--- a/src/dsp/platform.c
+++ b/src/dsp/platform.c
@@ -393,6 +393,24 @@
 	return PLDM_SUCCESS;
 }
 
+LIBPLDM_ABI_TESTING
+int encode_get_pdr_repository_info_req(uint8_t instance_id,
+				       struct pldm_msg *msg,
+				       size_t payload_length LIBPLDM_CC_UNUSED)
+{
+	if (!msg) {
+		return -EINVAL;
+	}
+
+	struct pldm_header_info header = { 0 };
+	header.msg_type = PLDM_REQUEST;
+	header.instance = instance_id;
+	header.pldm_type = PLDM_PLATFORM;
+	header.command = PLDM_GET_PDR_REPOSITORY_INFO;
+
+	return pack_pldm_header_errno(&header, &(msg->hdr));
+}
+
 LIBPLDM_ABI_STABLE
 int encode_get_pdr_repository_info_resp(
 	uint8_t instance_id, uint8_t completion_code, uint8_t repository_state,
diff --git a/tests/dsp/platform.cpp b/tests/dsp/platform.cpp
index e0032a2..0586c2e 100644
--- a/tests/dsp/platform.cpp
+++ b/tests/dsp/platform.cpp
@@ -533,6 +533,26 @@
 }
 #endif
 
+#ifdef LIBPLDM_API_TESTING
+TEST(GetPDRRepositoryInfo, testGoodEncodeRequest)
+{
+    pldm_msg request{};
+
+    auto rc = encode_get_pdr_repository_info_req(0, &request,
+                                                 sizeof(struct pldm_msg));
+    ASSERT_EQ(rc, PLDM_SUCCESS);
+}
+#endif
+
+#ifdef LIBPLDM_API_TESTING
+TEST(GetPDRRepositoryInfo, testBadEncodeRequest)
+{
+    auto rc =
+        encode_get_pdr_repository_info_req(0, nullptr, sizeof(struct pldm_msg));
+    EXPECT_EQ(rc, -EINVAL);
+}
+#endif
+
 TEST(GetPDRRepositoryInfo, testGoodEncodeResponse)
 {
     uint8_t completionCode = 0;