blob: 66b4ab597fefe24542f408c29fdf087e42364bcb [file] [log] [blame]
#include "firmware_update.h"
#include <endian.h>
int encode_query_device_identifiers_req(uint8_t instance_id,
size_t payload_length,
struct pldm_msg *msg)
{
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
if (payload_length != PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES) {
return PLDM_ERROR_INVALID_LENGTH;
}
return encode_pldm_header_only(PLDM_REQUEST, instance_id, PLDM_FWUP,
PLDM_QUERY_DEVICE_IDENTIFIERS, msg);
}
int decode_query_device_identifiers_resp(const struct pldm_msg *msg,
size_t payload_length,
uint8_t *completion_code,
uint32_t *device_identifiers_len,
uint8_t *descriptor_count,
uint8_t **descriptor_data)
{
if (msg == NULL || completion_code == NULL ||
device_identifiers_len == NULL || descriptor_count == NULL ||
descriptor_data == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
*completion_code = msg->payload[0];
if (PLDM_SUCCESS != *completion_code) {
return PLDM_SUCCESS;
}
if (payload_length <
sizeof(struct pldm_query_device_identifiers_resp)) {
return PLDM_ERROR_INVALID_LENGTH;
}
struct pldm_query_device_identifiers_resp *response =
(struct pldm_query_device_identifiers_resp *)msg->payload;
*device_identifiers_len = le32toh(response->device_identifiers_len);
if (*device_identifiers_len < PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN) {
return PLDM_ERROR_INVALID_LENGTH;
}
if (payload_length !=
sizeof(struct pldm_query_device_identifiers_resp) +
*device_identifiers_len) {
return PLDM_ERROR_INVALID_LENGTH;
}
*descriptor_count = response->descriptor_count;
if (*descriptor_count == 0) {
return PLDM_ERROR_INVALID_DATA;
}
*descriptor_data =
(uint8_t *)(msg->payload +
sizeof(struct pldm_query_device_identifiers_resp));
return PLDM_SUCCESS;
}
int encode_get_firmware_parameters_req(uint8_t instance_id,
size_t payload_length,
struct pldm_msg *msg)
{
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
if (payload_length != PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES) {
return PLDM_ERROR_INVALID_LENGTH;
}
return encode_pldm_header_only(PLDM_REQUEST, instance_id, PLDM_FWUP,
PLDM_GET_FIRMWARE_PARAMETERS, msg);
}