blob: 1c3e21bce6b47dccc02f433b1dddf1194f394b10 [file] [log] [blame]
gokulsanker138ceba2021-04-05 13:25:25 +05301#ifndef FW_UPDATE_H
2#define FW_UPDATE_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7#include "base.h"
gokulsanker22fbb342021-04-05 15:55:06 +05308#include "utils.h"
gokulsanker138ceba2021-04-05 13:25:25 +05309
10#define PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES 0
gokulsankereca3e192021-04-05 14:57:41 +053011/** @brief Minimum length of device descriptor, 2 bytes for descriptor type,
12 * 2 bytes for descriptor length and atleast 1 byte of descriptor data
13 */
14#define PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN 5
gokulsanker981fbfb2021-04-05 15:17:25 +053015#define PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES 0
gokulsanker138ceba2021-04-05 13:25:25 +053016
17/** @brief PLDM Firmware update commands
18 */
gokulsanker981fbfb2021-04-05 15:17:25 +053019enum pldm_firmware_update_commands {
20 PLDM_QUERY_DEVICE_IDENTIFIERS = 0x01,
21 PLDM_GET_FIRMWARE_PARAMETERS = 0x02
22};
gokulsanker138ceba2021-04-05 13:25:25 +053023
gokulsankereca3e192021-04-05 14:57:41 +053024/** @struct pldm_query_device_identifiers_resp
25 *
26 * Structure representing query device identifiers response.
27 */
28struct pldm_query_device_identifiers_resp {
29 uint8_t completion_code;
30 uint32_t device_identifiers_len;
31 uint8_t descriptor_count;
32} __attribute__((packed));
33
gokulsanker22fbb342021-04-05 15:55:06 +053034/** @struct pldm_get_firmware_parameters_resp
35 *
36 * Structure representing get firmware parameters response.
37 */
38struct pldm_get_firmware_parameters_resp {
39 uint8_t completion_code;
40 bitfield32_t capabilities_during_update;
41 uint16_t comp_count;
42 uint8_t active_comp_image_set_ver_str_type;
43 uint8_t active_comp_image_set_ver_str_len;
44 uint8_t pending_comp_image_set_ver_str_type;
45 uint8_t pending_comp_image_set_ver_str_len;
46} __attribute__((packed));
47
gokulsankere1fb7a82021-04-05 16:09:29 +053048/** @struct pldm_component_parameter_entry
49 *
50 * Structure representing component parameter table entry.
51 */
52struct pldm_component_parameter_entry {
53 uint16_t comp_classification;
54 uint16_t comp_identifier;
55 uint8_t comp_classification_index;
56 uint32_t active_comp_comparison_stamp;
57 uint8_t active_comp_ver_str_type;
58 uint8_t active_comp_ver_str_len;
59 uint8_t active_comp_release_date[8];
60 uint32_t pending_comp_comparison_stamp;
61 uint8_t pending_comp_ver_str_type;
62 uint8_t pending_comp_ver_str_len;
63 uint8_t pending_comp_release_date[8];
64 bitfield16_t comp_activation_methods;
65 bitfield32_t capabilities_during_update;
66} __attribute__((packed));
67
gokulsanker138ceba2021-04-05 13:25:25 +053068/** @brief Create a PLDM request message for QueryDeviceIdentifiers
69 *
70 * @param[in] instance_id - Message's instance id
71 * @param[in] payload_length - Length of the request message payload
72 * @param[in,out] msg - Message will be written to this
73 *
74 * @return pldm_completion_codes
75 *
76 * @note Caller is responsible for memory alloc and dealloc of param
77 * 'msg.payload'
78 */
79int encode_query_device_identifiers_req(uint8_t instance_id,
80 size_t payload_length,
81 struct pldm_msg *msg);
gokulsankereca3e192021-04-05 14:57:41 +053082
83/** @brief Decode QueryDeviceIdentifiers response message
84 *
85 * @param[in] msg - Response message
86 * @param[in] payload_length - Length of response message payload
87 * @param[out] completion_code - Pointer to response msg's PLDM completion code
88 * @param[out] device_identifiers_len - Pointer to device identifiers length
89 * @param[out] descriptor_count - Pointer to descriptor count
90 * @param[out] descriptor_data - Pointer to descriptor data
91 *
92 * @return pldm_completion_codes
93 */
94int decode_query_device_identifiers_resp(const struct pldm_msg *msg,
95 size_t payload_length,
96 uint8_t *completion_code,
97 uint32_t *device_identifiers_len,
98 uint8_t *descriptor_count,
99 uint8_t **descriptor_data);
gokulsanker981fbfb2021-04-05 15:17:25 +0530100
101/** @brief Create a PLDM request message for GetFirmwareParameters
102 *
103 * @param[in] instance_id - Message's instance id
104 * @param[in] payload_length - Length of the request message payload
105 * @param[in,out] msg - Message will be written to this
106 *
107 * @return pldm_completion_codes
108 *
109 * @note Caller is responsible for memory alloc and dealloc of param
110 * 'msg.payload'
111 */
112int encode_get_firmware_parameters_req(uint8_t instance_id,
113 size_t payload_length,
114 struct pldm_msg *msg);
gokulsanker22fbb342021-04-05 15:55:06 +0530115
116/** @brief Decode GetFirmwareParameters response parameters except the
117 * ComponentParameterTable
118 *
119 * @param[in] msg - Response message
120 * @param[in] payload_length - Length of response message payload
121 * @param[out] resp_data - Pointer to get firmware parameters response
122 * @param[out] active_comp_image_set_ver_str - Pointer to active component
123 * image set version string
124 * @param[out] pending_comp_image_set_ver_str - Pointer to pending component
125 * image set version string
126 *
127 * @return pldm_completion_codes
128 */
129int decode_get_firmware_parameters_resp_comp_set_info(
130 const struct pldm_msg *msg, size_t payload_length,
131 struct pldm_get_firmware_parameters_resp *resp_data,
132 struct variable_field *active_comp_image_set_ver_str,
133 struct variable_field *pending_comp_image_set_ver_str);
134
gokulsankere1fb7a82021-04-05 16:09:29 +0530135/** @brief Decode component entries in the component parameter table which is
136 * part of the response of GetFirmwareParameters command
137 *
138 * @param[in] data - Component entry
139 * @param[in] length - Length of component entry
140 * @param[out] component_data - Pointer to component parameter table
141 * @param[out] active_comp_ver_str - Pointer to active component version string
142 * @param[out] pending_comp_ver_str - Pointer to pending component version
143 * string
144 *
145 * @return pldm_completion_codes
146 */
147int decode_get_firmware_parameters_resp_comp_entry(
148 const uint8_t *data, size_t length,
149 struct pldm_component_parameter_entry *component_data,
150 struct variable_field *active_comp_ver_str,
151 struct variable_field *pending_comp_ver_str);
152
gokulsanker138ceba2021-04-05 13:25:25 +0530153#ifdef __cplusplus
154}
155#endif
156
157#endif // End of FW_UPDATE_H