transport: Use pldm_msg_hdr_correlate_response() for response correlation
Previously the correlation logic was open-coded in
pldm_transport_send_recv_msg(). Make use of
pldm_msg_hdr_correlate_response() internally as well, given logic is
already exposed for users of the asynchronous pldm_transport_send_msg()
and pldm_transport_recv_msg() APIs.
Change-Id: I332b8db0ff86e16bae6a7332f381ea0c439531a1
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/src/transport/transport.c b/src/transport/transport.c
index e6b02b1..12a26aa 100644
--- a/src/transport/transport.c
+++ b/src/transport/transport.c
@@ -203,8 +203,11 @@
return PLDM_REQUESTER_POLL_FAIL;
}
- do {
+ while (timercmp(&now, &end, <)) {
+ pldm_tid_t src_tid;
+
timersub(&end, &now, &remaining);
+
/* 0 <= `timeval_to_msec()` <= 4800, and 4800 < INT_MAX */
ret = pldm_transport_poll(transport,
(int)(timeval_to_msec(&remaining)));
@@ -217,23 +220,20 @@
return PLDM_REQUESTER_POLL_FAIL;
}
- pldm_tid_t src_tid;
rc = pldm_transport_recv_msg(transport, &src_tid, pldm_resp_msg,
resp_msg_len);
- if (rc == PLDM_REQUESTER_SUCCESS) {
- const struct pldm_msg_hdr *resp_hdr = *pldm_resp_msg;
- if ((src_tid == tid) &&
- (req_hdr->instance_id == resp_hdr->instance_id) &&
- (req_hdr->type == resp_hdr->type) &&
- (req_hdr->command == resp_hdr->command) &&
- !resp_hdr->request) {
- return rc;
- }
-
- /* This isn't the message we wanted */
- free(*pldm_resp_msg);
+ if (rc != PLDM_REQUESTER_SUCCESS) {
+ continue;
}
- } while (timercmp(&now, &end, <));
+
+ if (src_tid != tid || !pldm_msg_hdr_correlate_response(
+ pldm_req_msg, *pldm_resp_msg)) {
+ free(*pldm_resp_msg);
+ continue;
+ }
+
+ return PLDM_REQUESTER_SUCCESS;
+ }
return PLDM_REQUESTER_RECV_FAIL;
}