blob: a14bfb5f1defe812819f5cd1b9f6ba2046c2abb1 [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
Tom Joseph568e4702021-06-07 22:15:49 -070010#define PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE 8
gokulsanker138ceba2021-04-05 13:25:25 +053011#define PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES 0
gokulsankereca3e192021-04-05 14:57:41 +053012/** @brief Minimum length of device descriptor, 2 bytes for descriptor type,
13 * 2 bytes for descriptor length and atleast 1 byte of descriptor data
14 */
15#define PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN 5
gokulsanker981fbfb2021-04-05 15:17:25 +053016#define PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES 0
gokulsanker138ceba2021-04-05 13:25:25 +053017
18/** @brief PLDM Firmware update commands
19 */
gokulsanker981fbfb2021-04-05 15:17:25 +053020enum pldm_firmware_update_commands {
21 PLDM_QUERY_DEVICE_IDENTIFIERS = 0x01,
22 PLDM_GET_FIRMWARE_PARAMETERS = 0x02
23};
gokulsanker138ceba2021-04-05 13:25:25 +053024
Tom Joseph763b51e2021-06-05 04:50:47 -070025/** @brief String type values defined in the PLDM firmware update specification
26 */
27enum pldm_firmware_update_string_type {
28 PLDM_STR_TYPE_UNKNOWN = 0,
29 PLDM_STR_TYPE_ASCII = 1,
30 PLDM_STR_TYPE_UTF_8 = 2,
31 PLDM_STR_TYPE_UTF_16 = 3,
32 PLDM_STR_TYPE_UTF_16LE = 4,
33 PLDM_STR_TYPE_UTF_16BE = 5
34};
35
36/** @brief Descriptor types defined in PLDM firmware update specification
37 */
38enum pldm_firmware_update_descriptor_types {
39 PLDM_FWUP_PCI_VENDOR_ID = 0x0000,
40 PLDM_FWUP_IANA_ENTERPRISE_ID = 0x0001,
41 PLDM_FWUP_UUID = 0x0002,
42 PLDM_FWUP_PNP_VENDOR_ID = 0x0003,
43 PLDM_FWUP_ACPI_VENDOR_ID = 0x0004,
44 PLDM_FWUP_IEEE_ASSIGNED_COMPANY_ID = 0x0005,
45 PLDM_FWUP_SCSI_VENDOR_ID = 0x0006,
46 PLDM_FWUP_PCI_DEVICE_ID = 0x0100,
47 PLDM_FWUP_PCI_SUBSYSTEM_VENDOR_ID = 0x0101,
48 PLDM_FWUP_PCI_SUBSYSTEM_ID = 0x0102,
49 PLDM_FWUP_PCI_REVISION_ID = 0x0103,
50 PLDM_FWUP_PNP_PRODUCT_IDENTIFIER = 0x0104,
51 PLDM_FWUP_ACPI_PRODUCT_IDENTIFIER = 0x0105,
52 PLDM_FWUP_ASCII_MODEL_NUMBER_LONG_STRING = 0x0106,
53 PLDM_FWUP_ASCII_MODEL_NUMBER_SHORT_STRING = 0x0107,
54 PLDM_FWUP_SCSI_PRODUCT_ID = 0x0108,
55 PLDM_FWUP_UBM_CONTROLLER_DEVICE_CODE = 0x0109,
56 PLDM_FWUP_VENDOR_DEFINED = 0xFFFF
57};
58
59/** @brief Descriptor types length defined in PLDM firmware update specification
60 */
61enum pldm_firmware_update_descriptor_types_length {
62 PLDM_FWUP_PCI_VENDOR_ID_LENGTH = 2,
63 PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH = 4,
64 PLDM_FWUP_UUID_LENGTH = 16,
65 PLDM_FWUP_PNP_VENDOR_ID_LENGTH = 3,
66 PLDM_FWUP_ACPI_VENDOR_ID_LENGTH = 4,
67 PLDM_FWUP_IEEE_ASSIGNED_COMPANY_ID_LENGTH = 3,
68 PLDM_FWUP_SCSI_VENDOR_ID_LENGTH = 8,
69 PLDM_FWUP_PCI_DEVICE_ID_LENGTH = 2,
70 PLDM_FWUP_PCI_SUBSYSTEM_VENDOR_ID_LENGTH = 2,
71 PLDM_FWUP_PCI_SUBSYSTEM_ID_LENGTH = 2,
72 PLDM_FWUP_PCI_REVISION_ID_LENGTH = 1,
73 PLDM_FWUP_PNP_PRODUCT_IDENTIFIER_LENGTH = 4,
74 PLDM_FWUP_ACPI_PRODUCT_IDENTIFIER_LENGTH = 4,
75 PLDM_FWUP_ASCII_MODEL_NUMBER_LONG_STRING_LENGTH = 40,
76 PLDM_FWUP_ASCII_MODEL_NUMBER_SHORT_STRING_LENGTH = 10,
77 PLDM_FWUP_SCSI_PRODUCT_ID_LENGTH = 16,
78 PLDM_FWUP_UBM_CONTROLLER_DEVICE_CODE_LENGTH = 4
79};
80
Tom Joseph568e4702021-06-07 22:15:49 -070081/** @struct pldm_package_header_information
82 *
83 * Structure representing fixed part of package header information
84 */
85struct pldm_package_header_information {
86 uint8_t uuid[PLDM_FWUP_UUID_LENGTH];
87 uint8_t package_header_format_version;
88 uint16_t package_header_size;
89 uint8_t timestamp104[PLDM_TIMESTAMP104_SIZE];
90 uint16_t component_bitmap_bit_length;
91 uint8_t package_version_string_type;
92 uint8_t package_version_string_length;
93} __attribute__((packed));
94
Tom Joseph763b51e2021-06-05 04:50:47 -070095/** @struct pldm_descriptor_tlv
96 *
97 * Structure representing descriptor type, length and value
98 */
99struct pldm_descriptor_tlv {
100 uint16_t descriptor_type;
101 uint16_t descriptor_length;
102 uint8_t descriptor_data[1];
103} __attribute__((packed));
104
105/** @struct pldm_vendor_defined_descriptor_title_data
106 *
107 * Structure representing vendor defined descriptor title sections
108 */
109struct pldm_vendor_defined_descriptor_title_data {
110 uint8_t vendor_defined_descriptor_title_str_type;
111 uint8_t vendor_defined_descriptor_title_str_len;
112 uint8_t vendor_defined_descriptor_title_str[1];
113} __attribute__((packed));
114
gokulsankereca3e192021-04-05 14:57:41 +0530115/** @struct pldm_query_device_identifiers_resp
116 *
117 * Structure representing query device identifiers response.
118 */
119struct pldm_query_device_identifiers_resp {
120 uint8_t completion_code;
121 uint32_t device_identifiers_len;
122 uint8_t descriptor_count;
123} __attribute__((packed));
124
gokulsanker22fbb342021-04-05 15:55:06 +0530125/** @struct pldm_get_firmware_parameters_resp
126 *
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700127 * Structure representing the fixed part of GetFirmwareParameters response
gokulsanker22fbb342021-04-05 15:55:06 +0530128 */
129struct pldm_get_firmware_parameters_resp {
130 uint8_t completion_code;
131 bitfield32_t capabilities_during_update;
132 uint16_t comp_count;
133 uint8_t active_comp_image_set_ver_str_type;
134 uint8_t active_comp_image_set_ver_str_len;
135 uint8_t pending_comp_image_set_ver_str_type;
136 uint8_t pending_comp_image_set_ver_str_len;
137} __attribute__((packed));
138
gokulsankere1fb7a82021-04-05 16:09:29 +0530139/** @struct pldm_component_parameter_entry
140 *
141 * Structure representing component parameter table entry.
142 */
143struct pldm_component_parameter_entry {
144 uint16_t comp_classification;
145 uint16_t comp_identifier;
146 uint8_t comp_classification_index;
147 uint32_t active_comp_comparison_stamp;
148 uint8_t active_comp_ver_str_type;
149 uint8_t active_comp_ver_str_len;
150 uint8_t active_comp_release_date[8];
151 uint32_t pending_comp_comparison_stamp;
152 uint8_t pending_comp_ver_str_type;
153 uint8_t pending_comp_ver_str_len;
154 uint8_t pending_comp_release_date[8];
155 bitfield16_t comp_activation_methods;
156 bitfield32_t capabilities_during_update;
157} __attribute__((packed));
158
Tom Joseph568e4702021-06-07 22:15:49 -0700159/** @brief Decode the PLDM package header information
160 *
161 * @param[in] data - pointer to package header information
162 * @param[in] length - available length in the firmware update package
163 * @param[out] package_header_info - pointer to fixed part of PLDM package
164 * header information
165 * @param[out] package_version_str - pointer to package version string
166 *
167 * @return pldm_completion_codes
168 */
169int decode_pldm_package_header_info(
170 const uint8_t *data, size_t length,
171 struct pldm_package_header_information *package_header_info,
172 struct variable_field *package_version_str);
173
Tom Joseph763b51e2021-06-05 04:50:47 -0700174/** @brief Decode the record descriptor entries in the firmware update package
175 * and the Descriptors in the QueryDeviceIDentifiers command
176 *
177 * @param[in] data - pointer to descriptor entry
178 * @param[in] length - remaining length of the descriptor data
179 * @param[out] descriptor_type - pointer to descriptor type
180 * @param[out] descriptor_data - pointer to descriptor data
181 *
182 * @return pldm_completion_codes
183 */
184int decode_descriptor_type_length_value(const uint8_t *data, size_t length,
185 uint16_t *descriptor_type,
186 struct variable_field *descriptor_data);
187
188/** @brief Decode the vendor defined descriptor value
189 *
190 * @param[in] data - pointer to vendor defined descriptor value
191 * @param[in] length - length of the vendor defined descriptor value
192 * @param[out] descriptor_title_str_type - pointer to vendor defined descriptor
193 * title string type
194 * @param[out] descriptor_title_str - pointer to vendor defined descriptor
195 * title string
196 * @param[out] descriptor_data - pointer to vendor defined descriptor data
197 *
198 * @return pldm_completion_codes
199 */
200int decode_vendor_defined_descriptor_value(
201 const uint8_t *data, size_t length, uint8_t *descriptor_title_str_type,
202 struct variable_field *descriptor_title_str,
203 struct variable_field *descriptor_data);
204
gokulsanker138ceba2021-04-05 13:25:25 +0530205/** @brief Create a PLDM request message for QueryDeviceIdentifiers
206 *
207 * @param[in] instance_id - Message's instance id
208 * @param[in] payload_length - Length of the request message payload
209 * @param[in,out] msg - Message will be written to this
210 *
211 * @return pldm_completion_codes
212 *
213 * @note Caller is responsible for memory alloc and dealloc of param
214 * 'msg.payload'
215 */
216int encode_query_device_identifiers_req(uint8_t instance_id,
217 size_t payload_length,
218 struct pldm_msg *msg);
gokulsankereca3e192021-04-05 14:57:41 +0530219
220/** @brief Decode QueryDeviceIdentifiers response message
221 *
222 * @param[in] msg - Response message
223 * @param[in] payload_length - Length of response message payload
224 * @param[out] completion_code - Pointer to response msg's PLDM completion code
225 * @param[out] device_identifiers_len - Pointer to device identifiers length
226 * @param[out] descriptor_count - Pointer to descriptor count
227 * @param[out] descriptor_data - Pointer to descriptor data
228 *
229 * @return pldm_completion_codes
230 */
231int decode_query_device_identifiers_resp(const struct pldm_msg *msg,
232 size_t payload_length,
233 uint8_t *completion_code,
234 uint32_t *device_identifiers_len,
235 uint8_t *descriptor_count,
236 uint8_t **descriptor_data);
gokulsanker981fbfb2021-04-05 15:17:25 +0530237
238/** @brief Create a PLDM request message for GetFirmwareParameters
239 *
240 * @param[in] instance_id - Message's instance id
241 * @param[in] payload_length - Length of the request message payload
242 * @param[in,out] msg - Message will be written to this
243 *
244 * @return pldm_completion_codes
245 *
246 * @note Caller is responsible for memory alloc and dealloc of param
247 * 'msg.payload'
248 */
249int encode_get_firmware_parameters_req(uint8_t instance_id,
250 size_t payload_length,
251 struct pldm_msg *msg);
gokulsanker22fbb342021-04-05 15:55:06 +0530252
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700253/** @brief Decode GetFirmwareParameters response
gokulsanker22fbb342021-04-05 15:55:06 +0530254 *
255 * @param[in] msg - Response message
256 * @param[in] payload_length - Length of response message payload
257 * @param[out] resp_data - Pointer to get firmware parameters response
258 * @param[out] active_comp_image_set_ver_str - Pointer to active component
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700259 * image set version string
gokulsanker22fbb342021-04-05 15:55:06 +0530260 * @param[out] pending_comp_image_set_ver_str - Pointer to pending component
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700261 * image set version string
262 * @param[out] comp_parameter_table - Pointer to component parameter table
gokulsanker22fbb342021-04-05 15:55:06 +0530263 *
264 * @return pldm_completion_codes
265 */
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700266int decode_get_firmware_parameters_resp(
gokulsanker22fbb342021-04-05 15:55:06 +0530267 const struct pldm_msg *msg, size_t payload_length,
268 struct pldm_get_firmware_parameters_resp *resp_data,
269 struct variable_field *active_comp_image_set_ver_str,
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700270 struct variable_field *pending_comp_image_set_ver_str,
271 struct variable_field *comp_parameter_table);
gokulsanker22fbb342021-04-05 15:55:06 +0530272
gokulsankere1fb7a82021-04-05 16:09:29 +0530273/** @brief Decode component entries in the component parameter table which is
274 * part of the response of GetFirmwareParameters command
275 *
276 * @param[in] data - Component entry
277 * @param[in] length - Length of component entry
278 * @param[out] component_data - Pointer to component parameter table
279 * @param[out] active_comp_ver_str - Pointer to active component version string
280 * @param[out] pending_comp_ver_str - Pointer to pending component version
281 * string
282 *
283 * @return pldm_completion_codes
284 */
285int decode_get_firmware_parameters_resp_comp_entry(
286 const uint8_t *data, size_t length,
287 struct pldm_component_parameter_entry *component_data,
288 struct variable_field *active_comp_ver_str,
289 struct variable_field *pending_comp_ver_str);
290
gokulsanker138ceba2021-04-05 13:25:25 +0530291#ifdef __cplusplus
292}
293#endif
294
295#endif // End of FW_UPDATE_H