transport: Match specified metadata in pldm_transport_send_recv_msg()

The mctp-demux broadcasts the PLDM RX response messages to all of mctp
socket instances. That means the GetSensorReading response from one
instance (pldmd) can be received by the other instance (pldmtool)
which is waiting for the response of GetPDR request message. When the
gap time between the two requests of pldmtool is long enough the
number of GetSensorReading response messages can be more than 32. That
means the instance ID of new GetPDR command in pldmtool can equal with
the used and free one in GetSensorReading. So the
`pldm_transport_send_recv_msg()` will match the response of
GetSensorReading with the response of GetPDR. So only comparing the
instance ID in `pldm_transport_send_recv_msg` is not enough.

Section "Requirements for requesters" in DSP0240 version 1.1.0, "A
PLDM terminus that issues PLDM requests should be prepared to handle
the order of responses that may not match the order in which the
requests were sent (that is, it should not automatically assume that a
response that it receives is in the order in which the request was
sent). It should check to see that the PLDM Type, PLDM Command Code,
and Instance ID values in the response match up with a corresponding
outstanding command before acting on any parameters returned in the
response."

Add the PLDM type and command code on matching the response of
`pldm_transport_send_recv_msg()`.

Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
Change-Id: I7284bd4ecd8be3786fa078af1eb3f06046e4baa3
diff --git a/tests/transport.cpp b/tests/transport.cpp
index 0838751..4427896 100644
--- a/tests/transport.cpp
+++ b/tests/transport.cpp
@@ -271,3 +271,113 @@
     pldm_transport_test_destroy(test);
 }
 #endif
+
+#ifdef LIBPLDM_API_TESTING
+TEST(Transport, send_recv_wrong_pldm_type)
+{
+    uint8_t req[] = {0x81, 0x00, 0x01, 0x01};
+    uint8_t resp[] = {0x01, 0x01, 0x01, 0x00};
+    const struct pldm_transport_test_descriptor seq[] = {
+        {
+            .type = PLDM_TRANSPORT_TEST_ELEMENT_MSG_SEND,
+            .send_msg =
+                {
+                    .dst = 1,
+                    .msg = req,
+                    .len = sizeof(req),
+                },
+        },
+        {
+            .type = PLDM_TRANSPORT_TEST_ELEMENT_LATENCY,
+            .latency =
+                {
+                    .it_interval = {0, 0},
+                    .it_value = {1, 0},
+                },
+        },
+        {
+            .type = PLDM_TRANSPORT_TEST_ELEMENT_MSG_RECV,
+            .recv_msg =
+                {
+                    .src = 2,
+                    .msg = resp,
+                    .len = sizeof(resp),
+                },
+        },
+        {
+            .type = PLDM_TRANSPORT_TEST_ELEMENT_LATENCY,
+            .latency =
+                {
+                    .it_interval = {0, 0},
+                    .it_value = {4, 0},
+                },
+        },
+    };
+    struct pldm_transport_test* test = NULL;
+    struct pldm_transport* ctx;
+    size_t len;
+    void* msg;
+    int rc;
+
+    EXPECT_EQ(pldm_transport_test_init(&test, seq, ARRAY_SIZE(seq)), 0);
+    ctx = pldm_transport_test_core(test);
+    rc = pldm_transport_send_recv_msg(ctx, 1, req, sizeof(req), &msg, &len);
+    EXPECT_EQ(rc, PLDM_REQUESTER_RECV_FAIL);
+    pldm_transport_test_destroy(test);
+}
+#endif
+
+#ifdef LIBPLDM_API_TESTING
+TEST(Transport, send_recv_wrong_command_code)
+{
+    uint8_t req[] = {0x81, 0x00, 0x01, 0x01};
+    uint8_t resp[] = {0x01, 0x00, 0x02, 0x00};
+    const struct pldm_transport_test_descriptor seq[] = {
+        {
+            .type = PLDM_TRANSPORT_TEST_ELEMENT_MSG_SEND,
+            .send_msg =
+                {
+                    .dst = 1,
+                    .msg = req,
+                    .len = sizeof(req),
+                },
+        },
+        {
+            .type = PLDM_TRANSPORT_TEST_ELEMENT_LATENCY,
+            .latency =
+                {
+                    .it_interval = {0, 0},
+                    .it_value = {1, 0},
+                },
+        },
+        {
+            .type = PLDM_TRANSPORT_TEST_ELEMENT_MSG_RECV,
+            .recv_msg =
+                {
+                    .src = 2,
+                    .msg = resp,
+                    .len = sizeof(resp),
+                },
+        },
+        {
+            .type = PLDM_TRANSPORT_TEST_ELEMENT_LATENCY,
+            .latency =
+                {
+                    .it_interval = {0, 0},
+                    .it_value = {4, 0},
+                },
+        },
+    };
+    struct pldm_transport_test* test = NULL;
+    struct pldm_transport* ctx;
+    size_t len;
+    void* msg;
+    int rc;
+
+    EXPECT_EQ(pldm_transport_test_init(&test, seq, ARRAY_SIZE(seq)), 0);
+    ctx = pldm_transport_test_core(test);
+    rc = pldm_transport_send_recv_msg(ctx, 1, req, sizeof(req), &msg, &len);
+    EXPECT_EQ(rc, PLDM_REQUESTER_RECV_FAIL);
+    pldm_transport_test_destroy(test);
+}
+#endif