gokulsanker | 138ceba | 2021-04-05 13:25:25 +0530 | [diff] [blame] | 1 | #include "firmware_update.h"
|
gokulsanker | eca3e19 | 2021-04-05 14:57:41 +0530 | [diff] [blame^] | 2 | #include <endian.h>
|
gokulsanker | 138ceba | 2021-04-05 13:25:25 +0530 | [diff] [blame] | 3 |
|
| 4 | int encode_query_device_identifiers_req(uint8_t instance_id,
|
| 5 | size_t payload_length,
|
| 6 | struct pldm_msg *msg)
|
| 7 | {
|
| 8 | if (msg == NULL) {
|
| 9 | return PLDM_ERROR_INVALID_DATA;
|
| 10 | }
|
| 11 |
|
| 12 | if (payload_length != PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES) {
|
| 13 | return PLDM_ERROR_INVALID_LENGTH;
|
| 14 | }
|
| 15 |
|
| 16 | return encode_pldm_header_only(PLDM_REQUEST, instance_id, PLDM_FWUP,
|
| 17 | PLDM_QUERY_DEVICE_IDENTIFIERS, msg);
|
| 18 | }
|
gokulsanker | eca3e19 | 2021-04-05 14:57:41 +0530 | [diff] [blame^] | 19 |
|
| 20 | int decode_query_device_identifiers_resp(const struct pldm_msg *msg,
|
| 21 | size_t payload_length,
|
| 22 | uint8_t *completion_code,
|
| 23 | uint32_t *device_identifiers_len,
|
| 24 | uint8_t *descriptor_count,
|
| 25 | uint8_t **descriptor_data)
|
| 26 | {
|
| 27 | if (msg == NULL || completion_code == NULL ||
|
| 28 | device_identifiers_len == NULL || descriptor_count == NULL ||
|
| 29 | descriptor_data == NULL) {
|
| 30 | return PLDM_ERROR_INVALID_DATA;
|
| 31 | }
|
| 32 |
|
| 33 | *completion_code = msg->payload[0];
|
| 34 | if (PLDM_SUCCESS != *completion_code) {
|
| 35 | return PLDM_SUCCESS;
|
| 36 | }
|
| 37 |
|
| 38 | if (payload_length <
|
| 39 | sizeof(struct pldm_query_device_identifiers_resp)) {
|
| 40 | return PLDM_ERROR_INVALID_LENGTH;
|
| 41 | }
|
| 42 |
|
| 43 | struct pldm_query_device_identifiers_resp *response =
|
| 44 | (struct pldm_query_device_identifiers_resp *)msg->payload;
|
| 45 | *device_identifiers_len = le32toh(response->device_identifiers_len);
|
| 46 |
|
| 47 | if (*device_identifiers_len < PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN) {
|
| 48 | return PLDM_ERROR_INVALID_LENGTH;
|
| 49 | }
|
| 50 |
|
| 51 | if (payload_length !=
|
| 52 | sizeof(struct pldm_query_device_identifiers_resp) +
|
| 53 | *device_identifiers_len) {
|
| 54 | return PLDM_ERROR_INVALID_LENGTH;
|
| 55 | }
|
| 56 | *descriptor_count = response->descriptor_count;
|
| 57 |
|
| 58 | if (*descriptor_count == 0) {
|
| 59 | return PLDM_ERROR_INVALID_DATA;
|
| 60 | }
|
| 61 |
|
| 62 | *descriptor_data =
|
| 63 | (uint8_t *)(msg->payload +
|
| 64 | sizeof(struct pldm_query_device_identifiers_resp));
|
| 65 | return PLDM_SUCCESS;
|
| 66 | }
|