platform: fix encode/decode_poll_for_platform_event_message_req
The checking `TransferOperationFlag` and `eventIDToAcknowledge` in
`encode/decode_poll_for_platform_event_message_req` APIs is not
corrected. Update the conditions to follow the section `16.7
PollForPlatformEventMessage command` in DSP0248 V1.3.0.
Change-Id: Ie799d38f4a492b7719c2ff7c14fe83a1f81dc0b1
Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
diff --git a/src/dsp/platform.c b/src/dsp/platform.c
index 76b8992..4ecad13 100644
--- a/src/dsp/platform.c
+++ b/src/dsp/platform.c
@@ -1046,6 +1046,22 @@
return pldm_msgbuf_destroy(buf);
}
+static int pldm_platform_poll_for_platform_event_message_validate(
+ uint8_t transfer_operation_flag, uint16_t event_id_to_acknowledge)
+{
+ if (((transfer_operation_flag == PLDM_GET_FIRSTPART) &&
+ (event_id_to_acknowledge != PLDM_PLATFORM_EVENT_ID_NULL)) ||
+ ((transfer_operation_flag == PLDM_GET_NEXTPART) &&
+ (event_id_to_acknowledge != PLDM_PLATFORM_EVENT_ID_FRAGMENT)) ||
+ ((transfer_operation_flag == PLDM_ACKNOWLEDGEMENT_ONLY) &&
+ (event_id_to_acknowledge != PLDM_PLATFORM_EVENT_ID_FRAGMENT)) ||
+ (transfer_operation_flag > PLDM_ACKNOWLEDGEMENT_ONLY)) {
+ return -EPROTO;
+ }
+
+ return 0;
+}
+
LIBPLDM_ABI_STABLE
int decode_poll_for_platform_event_message_req(
const struct pldm_msg *msg, size_t payload_length,
@@ -1084,11 +1100,9 @@
return rc;
}
- if (!(((*transfer_operation_flag == PLDM_GET_NEXTPART) &&
- (*event_id_to_acknowledge == 0xffff)) ||
- ((*transfer_operation_flag == PLDM_GET_FIRSTPART) &&
- (*event_id_to_acknowledge == 0x000)) ||
- (*transfer_operation_flag == PLDM_ACKNOWLEDGEMENT_ONLY))) {
+ rc = pldm_platform_poll_for_platform_event_message_validate(
+ *transfer_operation_flag, *event_id_to_acknowledge);
+ if (rc < 0) {
return PLDM_ERROR_INVALID_DATA;
}
@@ -2473,6 +2487,12 @@
return PLDM_ERROR_INVALID_DATA;
}
+ rc = pldm_platform_poll_for_platform_event_message_validate(
+ transfer_operation_flag, event_id_to_acknowledge);
+ if (rc < 0) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
struct pldm_header_info header = { 0 };
header.msg_type = PLDM_REQUEST;
header.instance = instance_id;