blob: 66b4ab597fefe24542f408c29fdf087e42364bcb [file] [log] [blame]
gokulsanker138ceba2021-04-05 13:25:25 +05301#include "firmware_update.h"
gokulsankereca3e192021-04-05 14:57:41 +05302#include <endian.h>
gokulsanker138ceba2021-04-05 13:25:25 +05303
4int 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}
gokulsankereca3e192021-04-05 14:57:41 +053019
20int 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 }
gokulsankereca3e192021-04-05 14:57:41 +053061 *descriptor_data =
62 (uint8_t *)(msg->payload +
63 sizeof(struct pldm_query_device_identifiers_resp));
64 return PLDM_SUCCESS;
65}
gokulsanker981fbfb2021-04-05 15:17:25 +053066
67int encode_get_firmware_parameters_req(uint8_t instance_id,
68 size_t payload_length,
69 struct pldm_msg *msg)
70{
71 if (msg == NULL) {
72 return PLDM_ERROR_INVALID_DATA;
73 }
74
75 if (payload_length != PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES) {
76 return PLDM_ERROR_INVALID_LENGTH;
77 }
78
79 return encode_pldm_header_only(PLDM_REQUEST, instance_id, PLDM_FWUP,
80 PLDM_GET_FIRMWARE_PARAMETERS, msg);
81}