1 /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
2 #ifndef FW_UPDATE_H
3 #define FW_UPDATE_H
4 
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8 
9 #include <libpldm/api.h>
10 #include <libpldm/base.h>
11 #include <libpldm/pldm_types.h>
12 #include <libpldm/utils.h>
13 
14 #include <stdbool.h>
15 #include <stddef.h>
16 #include <stdint.h>
17 
18 #define PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE		 8
19 #define PLDM_FWUP_INVALID_COMPONENT_COMPARISON_TIMESTAMP 0xffffffff
20 #define PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES		 0
21 
22 /** @brief Length of QueryDownstreamDevices response defined in DSP0267_1.1.0
23  *  Table 15 - QueryDownstreamDevices command format.
24  *
25  *  1 byte for completion code
26  *  1 byte for downstream device update supported
27  *  2 bytes for number of downstream devices
28  *  2 bytes for max number of downstream devices
29  *  4 bytes for capabilities
30  */
31 #define PLDM_QUERY_DOWNSTREAM_DEVICES_RESP_BYTES 10
32 
33 /** @brief Length of QueryDownstreamIdentifiers request defined in DSP0267_1.1.0
34  * 	Table 16 - QueryDownstreamIdentifiers command format.
35  *
36  *  4 bytes for data transfer handle
37  *  1 byte for transfer operation flag
38 */
39 #define PLDM_QUERY_DOWNSTREAM_IDENTIFIERS_REQ_BYTES 5
40 
41 /** @brief Minimum length of QueryDownstreamIdentifiers response from DSP0267_1.1.0
42  *  if the complement code is success.
43  *
44  *  1 byte for completion code
45  *  4 bytes for next data transfer handle
46  *  1 byte for transfer flag
47  *  4 bytes for downstream devices length
48  *  2 bytes for number of downstream devices
49  */
50 #define PLDM_QUERY_DOWNSTREAM_IDENTIFIERS_RESP_MIN_LEN 12
51 
52 /** @brief Minimum length of device descriptor, 2 bytes for descriptor type,
53  *         2 bytes for descriptor length and at least 1 byte of descriptor data
54  */
55 #define PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN 5
56 
57 /** @brief Length of GetDownstreamFirmwareParameters request defined in DSP0267_1.1.0
58  *
59  * 4 bytes for Data Transfer Handle
60  * 1 byte for Transfer Operation Flag
61  */
62 #define PLDM_GET_DOWNSTREAM_FIRMWARE_PARAMETERS_REQ_BYTES 5
63 
64 /** @brief Minimum length of GetDownstreamFirmwareParameters response from
65  * DSP0267_1.1.0 if the completion code is success.
66  *
67  * 1 byte for completion code
68  * 4 bytes for next data transfer handle
69  * 1 byte for transfer flag
70  * 4 bytes for FDP capabilities during update
71  * 2 bytes for downstream device count
72  */
73 #define PLDM_GET_DOWNSTREAM_FIRMWARE_PARAMETERS_RESP_MIN_LEN 12
74 
75 /** @brief Minimum length of DownstreamDeviceParameterTable entry from
76  * DSP0267_1.1.0 table 21 - DownstreamDeviceParameterTable
77  *
78  * 2 bytes for Downstream Device Index
79  * 4 bytes for Active Component Comparison Stamp
80  * 1 byte for Active Component Version String Type
81  * 1 byte for Active Component Version String Length
82  * 8 bytes for Active Component Release Date
83  * 4 bytes for Pending Component Comparison Stamp
84  * 1 byte for Pending Component Version String Type
85  * 1 byte for Pending Component Version String Length
86  * 8 bytes for Pending Component Release Date
87  * 2 bytes for Component Activation Methods
88  * 4 bytes for Capabilities During Update
89  */
90 #define PLDM_DOWNSTREAM_DEVICE_PARAMETERS_ENTRY_MIN_LEN 36
91 
92 #define PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES 0
93 #define PLDM_FWUP_BASELINE_TRANSFER_SIZE       32
94 #define PLDM_FWUP_MIN_OUTSTANDING_REQ	       1
95 #define PLDM_GET_STATUS_REQ_BYTES	       0
96 /* Maximum progress percentage value*/
97 #define PLDM_FWUP_MAX_PROGRESS_PERCENT	       0x65
98 #define PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES 0
99 #define PLDM_CANCEL_UPDATE_REQ_BYTES	       0
100 
101 /** @brief PLDM component release data size in bytes defined in DSP0267_1.1.0
102  * Table 14 - ComponentParameterTable and Table 21 - ComponentParameterTable
103  *
104  * The size can be used in `ASCII[8] - ActiveComponentReleaseDate` and
105  * `ASCII[8] - PendingComponentReleaseDate` fields in the tables above.
106  */
107 #define PLDM_FWUP_COMPONENT_RELEASE_DATA_LEN 8
108 
109 /** @brief PLDM Firmware update commands
110  */
111 enum pldm_firmware_update_commands {
112 	PLDM_QUERY_DEVICE_IDENTIFIERS = 0x01,
113 	PLDM_GET_FIRMWARE_PARAMETERS = 0x02,
114 	PLDM_QUERY_DOWNSTREAM_DEVICES = 0x03,
115 	PLDM_QUERY_DOWNSTREAM_IDENTIFIERS = 0x04,
116 	PLDM_QUERY_DOWNSTREAM_FIRMWARE_PARAMETERS = 0x05,
117 	PLDM_REQUEST_UPDATE = 0x10,
118 	PLDM_PASS_COMPONENT_TABLE = 0x13,
119 	PLDM_UPDATE_COMPONENT = 0x14,
120 	PLDM_REQUEST_FIRMWARE_DATA = 0x15,
121 	PLDM_TRANSFER_COMPLETE = 0x16,
122 	PLDM_VERIFY_COMPLETE = 0x17,
123 	PLDM_APPLY_COMPLETE = 0x18,
124 	PLDM_ACTIVATE_FIRMWARE = 0x1a,
125 	PLDM_GET_STATUS = 0x1b,
126 	PLDM_CANCEL_UPDATE_COMPONENT = 0x1c,
127 	PLDM_CANCEL_UPDATE = 0x1d
128 };
129 
130 /** @brief PLDM Firmware update completion codes
131  */
132 enum pldm_firmware_update_completion_codes {
133 	PLDM_FWUP_NOT_IN_UPDATE_MODE = 0x80,
134 	PLDM_FWUP_ALREADY_IN_UPDATE_MODE = 0x81,
135 	PLDM_FWUP_DATA_OUT_OF_RANGE = 0x82,
136 	PLDM_FWUP_INVALID_TRANSFER_LENGTH = 0x83,
137 	PLDM_FWUP_INVALID_STATE_FOR_COMMAND = 0x84,
138 	PLDM_FWUP_INCOMPLETE_UPDATE = 0x85,
139 	PLDM_FWUP_BUSY_IN_BACKGROUND = 0x86,
140 	PLDM_FWUP_CANCEL_PENDING = 0x87,
141 	PLDM_FWUP_COMMAND_NOT_EXPECTED = 0x88,
142 	PLDM_FWUP_RETRY_REQUEST_FW_DATA = 0x89,
143 	PLDM_FWUP_UNABLE_TO_INITIATE_UPDATE = 0x8a,
144 	PLDM_FWUP_ACTIVATION_NOT_REQUIRED = 0x8b,
145 	PLDM_FWUP_SELF_CONTAINED_ACTIVATION_NOT_PERMITTED = 0x8c,
146 	PLDM_FWUP_NO_DEVICE_METADATA = 0x8d,
147 	PLDM_FWUP_RETRY_REQUEST_UPDATE = 0x8e,
148 	PLDM_FWUP_NO_PACKAGE_DATA = 0x8f,
149 	PLDM_FWUP_INVALID_TRANSFER_HANDLE = 0x90,
150 	PLDM_FWUP_INVALID_TRANSFER_OPERATION_FLAG = 0x91,
151 	PLDM_FWUP_ACTIVATE_PENDING_IMAGE_NOT_PERMITTED = 0x92,
152 	PLDM_FWUP_PACKAGE_DATA_ERROR = 0x93
153 };
154 
155 /** @brief String type values defined in the PLDM firmware update specification
156  */
157 enum pldm_firmware_update_string_type {
158 	PLDM_STR_TYPE_UNKNOWN = 0,
159 	PLDM_STR_TYPE_ASCII = 1,
160 	PLDM_STR_TYPE_UTF_8 = 2,
161 	PLDM_STR_TYPE_UTF_16 = 3,
162 	PLDM_STR_TYPE_UTF_16LE = 4,
163 	PLDM_STR_TYPE_UTF_16BE = 5
164 };
165 
166 /** @brief Descriptor types defined in PLDM firmware update specification
167  */
168 enum pldm_firmware_update_descriptor_types {
169 	PLDM_FWUP_PCI_VENDOR_ID = 0x0000,
170 	PLDM_FWUP_IANA_ENTERPRISE_ID = 0x0001,
171 	PLDM_FWUP_UUID = 0x0002,
172 	PLDM_FWUP_PNP_VENDOR_ID = 0x0003,
173 	PLDM_FWUP_ACPI_VENDOR_ID = 0x0004,
174 	PLDM_FWUP_IEEE_ASSIGNED_COMPANY_ID = 0x0005,
175 	PLDM_FWUP_SCSI_VENDOR_ID = 0x0006,
176 	PLDM_FWUP_PCI_DEVICE_ID = 0x0100,
177 	PLDM_FWUP_PCI_SUBSYSTEM_VENDOR_ID = 0x0101,
178 	PLDM_FWUP_PCI_SUBSYSTEM_ID = 0x0102,
179 	PLDM_FWUP_PCI_REVISION_ID = 0x0103,
180 	PLDM_FWUP_PNP_PRODUCT_IDENTIFIER = 0x0104,
181 	PLDM_FWUP_ACPI_PRODUCT_IDENTIFIER = 0x0105,
182 	PLDM_FWUP_ASCII_MODEL_NUMBER_LONG_STRING = 0x0106,
183 	PLDM_FWUP_ASCII_MODEL_NUMBER_SHORT_STRING = 0x0107,
184 	PLDM_FWUP_SCSI_PRODUCT_ID = 0x0108,
185 	PLDM_FWUP_UBM_CONTROLLER_DEVICE_CODE = 0x0109,
186 	PLDM_FWUP_VENDOR_DEFINED = 0xffff
187 };
188 
189 /** @brief Descriptor types length defined in PLDM firmware update specification
190  */
191 enum pldm_firmware_update_descriptor_types_length {
192 	PLDM_FWUP_PCI_VENDOR_ID_LENGTH = 2,
193 	PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH = 4,
194 	PLDM_FWUP_UUID_LENGTH = 16,
195 	PLDM_FWUP_PNP_VENDOR_ID_LENGTH = 3,
196 	PLDM_FWUP_ACPI_VENDOR_ID_LENGTH = 4,
197 	PLDM_FWUP_IEEE_ASSIGNED_COMPANY_ID_LENGTH = 3,
198 	PLDM_FWUP_SCSI_VENDOR_ID_LENGTH = 8,
199 	PLDM_FWUP_PCI_DEVICE_ID_LENGTH = 2,
200 	PLDM_FWUP_PCI_SUBSYSTEM_VENDOR_ID_LENGTH = 2,
201 	PLDM_FWUP_PCI_SUBSYSTEM_ID_LENGTH = 2,
202 	PLDM_FWUP_PCI_REVISION_ID_LENGTH = 1,
203 	PLDM_FWUP_PNP_PRODUCT_IDENTIFIER_LENGTH = 4,
204 	PLDM_FWUP_ACPI_PRODUCT_IDENTIFIER_LENGTH = 4,
205 	PLDM_FWUP_ASCII_MODEL_NUMBER_LONG_STRING_LENGTH = 40,
206 	PLDM_FWUP_ASCII_MODEL_NUMBER_SHORT_STRING_LENGTH = 10,
207 	PLDM_FWUP_SCSI_PRODUCT_ID_LENGTH = 16,
208 	PLDM_FWUP_UBM_CONTROLLER_DEVICE_CODE_LENGTH = 4
209 };
210 
211 /** @brief ComponentClassification values defined in firmware update
212  *         specification
213  */
214 enum pldm_component_classification_values {
215 	PLDM_COMP_UNKNOWN = 0x0000,
216 	PLDM_COMP_OTHER = 0x0001,
217 	PLDM_COMP_DRIVER = 0x0002,
218 	PLDM_COMP_CONFIGURATION_SOFTWARE = 0x0003,
219 	PLDM_COMP_APPLICATION_SOFTWARE = 0x0004,
220 	PLDM_COMP_INSTRUMENTATION = 0x0005,
221 	PLDM_COMP_FIRMWARE_OR_BIOS = 0x0006,
222 	PLDM_COMP_DIAGNOSTIC_SOFTWARE = 0x0007,
223 	PLDM_COMP_OPERATING_SYSTEM = 0x0008,
224 	PLDM_COMP_MIDDLEWARE = 0x0009,
225 	PLDM_COMP_FIRMWARE = 0x000a,
226 	PLDM_COMP_BIOS_OR_FCODE = 0x000b,
227 	PLDM_COMP_SUPPORT_OR_SERVICEPACK = 0x000c,
228 	PLDM_COMP_SOFTWARE_BUNDLE = 0x000d,
229 	PLDM_COMP_DOWNSTREAM_DEVICE = 0xffff
230 };
231 
232 /** @brief ComponentActivationMethods is the bit position in the bitfield that
233  *         provides the capability of the FD for firmware activation. Multiple
234  *         activation methods can be supported.
235  */
236 enum pldm_comp_activation_methods {
237 	PLDM_ACTIVATION_AUTOMATIC = 0,
238 	PLDM_ACTIVATION_SELF_CONTAINED = 1,
239 	PLDM_ACTIVATION_MEDIUM_SPECIFIC_RESET = 2,
240 	PLDM_ACTIVATION_SYSTEM_REBOOT = 3,
241 	PLDM_ACTIVATION_DC_POWER_CYCLE = 4,
242 	PLDM_ACTIVATION_AC_POWER_CYCLE = 5,
243 	PLDM_SUPPORTS_ACTIVATE_PENDING_IMAGE = 6,
244 	PLDM_SUPPORTS_ACTIVATE_PENDING_IMAGE_SET = 7
245 };
246 
247 /** @brief ComponentResponse values in the response of PassComponentTable
248  */
249 enum pldm_component_responses {
250 	PLDM_CR_COMP_CAN_BE_UPDATED = 0,
251 	PLDM_CR_COMP_MAY_BE_UPDATEABLE = 1
252 };
253 
254 /** @brief ComponentResponseCode values in the response of PassComponentTable
255  */
256 enum pldm_component_response_codes {
257 	PLDM_CRC_COMP_CAN_BE_UPDATED = 0x00,
258 	PLDM_CRC_COMP_COMPARISON_STAMP_IDENTICAL = 0x01,
259 	PLDM_CRC_COMP_COMPARISON_STAMP_LOWER = 0x02,
260 	PLDM_CRC_INVALID_COMP_COMPARISON_STAMP = 0x03,
261 	PLDM_CRC_COMP_CONFLICT = 0x04,
262 	PLDM_CRC_COMP_PREREQUISITES_NOT_MET = 0x05,
263 	PLDM_CRC_COMP_NOT_SUPPORTED = 0x06,
264 	PLDM_CRC_COMP_SECURITY_RESTRICTIONS = 0x07,
265 	PLDM_CRC_INCOMPLETE_COMP_IMAGE_SET = 0x08,
266 	PLDM_CRC_ACTIVE_IMAGE_NOT_UPDATEABLE_SUBSEQUENTLY = 0x09,
267 	PLDM_CRC_COMP_VER_STR_IDENTICAL = 0x0a,
268 	PLDM_CRC_COMP_VER_STR_LOWER = 0x0b,
269 	PLDM_CRC_VENDOR_COMP_RESP_CODE_RANGE_MIN = 0xd0,
270 	PLDM_CRC_VENDOR_COMP_RESP_CODE_RANGE_MAX = 0xef
271 };
272 
273 /** @brief ComponentCompatibilityResponse values in the response of
274  *         UpdateComponent
275  */
276 enum pldm_component_compatibility_responses {
277 	PLDM_CCR_COMP_CAN_BE_UPDATED = 0,
278 	PLDM_CCR_COMP_CANNOT_BE_UPDATED = 1
279 };
280 
281 /** @brief ComponentCompatibilityResponse Code values in the response of
282  *         UpdateComponent
283  */
284 enum pldm_component_compatibility_response_codes {
285 	PLDM_CCRC_NO_RESPONSE_CODE = 0x00,
286 	PLDM_CCRC_COMP_COMPARISON_STAMP_IDENTICAL = 0x01,
287 	PLDM_CCRC_COMP_COMPARISON_STAMP_LOWER = 0x02,
288 	PLDM_CCRC_INVALID_COMP_COMPARISON_STAMP = 0x03,
289 	PLDM_CCRC_COMP_CONFLICT = 0x04,
290 	PLDM_CCRC_COMP_PREREQUISITES_NOT_MET = 0x05,
291 	PLDM_CCRC_COMP_NOT_SUPPORTED = 0x06,
292 	PLDM_CCRC_COMP_SECURITY_RESTRICTIONS = 0x07,
293 	PLDM_CCRC_INCOMPLETE_COMP_IMAGE_SET = 0x08,
294 	PLDM_CCRC_COMP_INFO_NO_MATCH = 0x09,
295 	PLDM_CCRC_COMP_VER_STR_IDENTICAL = 0x0a,
296 	PLDM_CCRC_COMP_VER_STR_LOWER = 0x0b,
297 	PLDM_CCRC_VENDOR_COMP_RESP_CODE_RANGE_MIN = 0xd0,
298 	PLDM_CCRC_VENDOR_COMP_RESP_CODE_RANGE_MAX = 0xef
299 };
300 
301 /** @brief Common error codes in TransferComplete, VerifyComplete and
302  *        ApplyComplete request
303  */
304 enum pldm_firmware_update_common_error_codes {
305 	PLDM_FWUP_TIME_OUT = 0x09,
306 	PLDM_FWUP_GENERIC_ERROR = 0x0a
307 };
308 
309 /** @brief TransferResult values in the request of TransferComplete
310  */
311 enum pldm_firmware_update_transfer_result_values {
312 	PLDM_FWUP_TRANSFER_SUCCESS = 0x00,
313 	PLDM_FWUP_TRANSFER_ERROR_IMAGE_CORRUPT = 0x02,
314 	PLDM_FWUP_TRANSFER_ERROR_VERSION_MISMATCH = 0x02,
315 	PLDM_FWUP_FD_ABORTED_TRANSFER = 0x03,
316 	PLDM_FWUP_FD_ABORTED_TRANSFER_LOW_POWER_STATE = 0x0b,
317 	PLDM_FWUP_FD_ABORTED_TRANSFER_RESET_NEEDED = 0x0c,
318 	PLDM_FWUP_FD_ABORTED_TRANSFER_STORAGE_ISSUE = 0x0d,
319 	PLDM_FWUP_VENDOR_TRANSFER_RESULT_RANGE_MIN = 0x70,
320 	PLDM_FWUP_VENDOR_TRANSFER_RESULT_RANGE_MAX = 0x8f
321 };
322 
323 /**@brief VerifyResult values in the request of VerifyComplete
324  */
325 enum pldm_firmware_update_verify_result_values {
326 	PLDM_FWUP_VERIFY_SUCCESS = 0x00,
327 	PLDM_FWUP_VERIFY_ERROR_VERIFICATION_FAILURE = 0x01,
328 	PLDM_FWUP_VERIFY_ERROR_VERSION_MISMATCH = 0x02,
329 	PLDM_FWUP_VERIFY_FAILED_FD_SECURITY_CHECKS = 0x03,
330 	PLDM_FWUP_VERIFY_ERROR_IMAGE_INCOMPLETE = 0x04,
331 	PLDM_FWUP_VENDOR_VERIFY_RESULT_RANGE_MIN = 0x90,
332 	PLDM_FWUP_VENDOR_VERIFY_RESULT_RANGE_MAX = 0xaf
333 };
334 
335 /**@brief ApplyResult values in the request of ApplyComplete
336  */
337 enum pldm_firmware_update_apply_result_values {
338 	PLDM_FWUP_APPLY_SUCCESS = 0x00,
339 	PLDM_FWUP_APPLY_SUCCESS_WITH_ACTIVATION_METHOD = 0x01,
340 	PLDM_FWUP_APPLY_FAILURE_MEMORY_ISSUE = 0x02,
341 	PLDM_FWUP_VENDOR_APPLY_RESULT_RANGE_MIN = 0xb0,
342 	PLDM_FWUP_VENDOR_APPLY_RESULT_RANGE_MAX = 0xcf
343 };
344 
345 /** @brief SelfContainedActivationRequest in the request of ActivateFirmware
346  */
347 enum pldm_self_contained_activation_req {
348 	PLDM_NOT_ACTIVATE_SELF_CONTAINED_COMPONENTS = false,
349 	PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS = true
350 };
351 
352 /** @brief Current state/previous state of the FD or FDP returned in GetStatus
353  *         response
354  */
355 enum pldm_firmware_device_states {
356 	PLDM_FD_STATE_IDLE = 0,
357 	PLDM_FD_STATE_LEARN_COMPONENTS = 1,
358 	PLDM_FD_STATE_READY_XFER = 2,
359 	PLDM_FD_STATE_DOWNLOAD = 3,
360 	PLDM_FD_STATE_VERIFY = 4,
361 	PLDM_FD_STATE_APPLY = 5,
362 	PLDM_FD_STATE_ACTIVATE = 6
363 };
364 
365 /** @brief Firmware device aux state in GetStatus response
366  */
367 enum pldm_get_status_aux_states {
368 	PLDM_FD_OPERATION_IN_PROGRESS = 0,
369 	PLDM_FD_OPERATION_SUCCESSFUL = 1,
370 	PLDM_FD_OPERATION_FAILED = 2,
371 	PLDM_FD_IDLE_LEARN_COMPONENTS_READ_XFER = 3
372 };
373 
374 /** @brief Firmware device aux state status in GetStatus response
375  */
376 enum pldm_get_status_aux_state_status_values {
377 	PLDM_FD_AUX_STATE_IN_PROGRESS_OR_SUCCESS = 0x00,
378 	PLDM_FD_TIMEOUT = 0x09,
379 	PLDM_FD_GENERIC_ERROR = 0x0a,
380 	PLDM_FD_VENDOR_DEFINED_STATUS_CODE_START = 0x70,
381 	PLDM_FD_VENDOR_DEFINED_STATUS_CODE_END = 0xef
382 };
383 
384 /** @brief Firmware device reason code in GetStatus response
385  */
386 enum pldm_get_status_reason_code_values {
387 	PLDM_FD_INITIALIZATION = 0,
388 	PLDM_FD_ACTIVATE_FW = 1,
389 	PLDM_FD_CANCEL_UPDATE = 2,
390 	PLDM_FD_TIMEOUT_LEARN_COMPONENT = 3,
391 	PLDM_FD_TIMEOUT_READY_XFER = 4,
392 	PLDM_FD_TIMEOUT_DOWNLOAD = 5,
393 	PLDM_FD_TIMEOUT_VERIFY = 6,
394 	PLDM_FD_TIMEOUT_APPLY = 7,
395 	PLDM_FD_STATUS_VENDOR_DEFINED_MIN = 200,
396 	PLDM_FD_STATUS_VENDOR_DEFINED_MAX = 255
397 };
398 
399 /** @brief Components functional indicator in CancelUpdate response
400  */
401 enum pldm_firmware_update_non_functioning_component_indication {
402 	PLDM_FWUP_COMPONENTS_FUNCTIONING = 0,
403 	PLDM_FWUP_COMPONENTS_NOT_FUNCTIONING = 1
404 };
405 
406 /** @brief Downstream device update supported in QueryDownstreamDevices response
407  *         defined in DSP0267_1.1.0
408 */
409 enum pldm_firmware_update_downstream_device_update_supported {
410 	PLDM_FWUP_DOWNSTREAM_DEVICE_UPDATE_NOT_SUPPORTED = 0,
411 	PLDM_FWUP_DOWNSTREAM_DEVICE_UPDATE_SUPPORTED = 1
412 };
413 
414 /** @struct pldm_package_header_information
415  *
416  *  Structure representing fixed part of package header information
417  */
418 struct pldm_package_header_information {
419 	uint8_t uuid[PLDM_FWUP_UUID_LENGTH];
420 	uint8_t package_header_format_version;
421 	uint16_t package_header_size;
422 	uint8_t package_release_date_time[PLDM_TIMESTAMP104_SIZE];
423 	uint16_t component_bitmap_bit_length;
424 	uint8_t package_version_string_type;
425 	uint8_t package_version_string_length;
426 } __attribute__((packed));
427 
428 /** @struct pldm_firmware_device_id_record
429  *
430  *  Structure representing firmware device ID record
431  */
432 struct pldm_firmware_device_id_record {
433 	uint16_t record_length;
434 	uint8_t descriptor_count;
435 	bitfield32_t device_update_option_flags;
436 	uint8_t comp_image_set_version_string_type;
437 	uint8_t comp_image_set_version_string_length;
438 	uint16_t fw_device_pkg_data_length;
439 } __attribute__((packed));
440 
441 /** @struct pldm_descriptor_tlv
442  *
443  *  Structure representing descriptor type, length and value
444  */
445 struct pldm_descriptor_tlv {
446 	uint16_t descriptor_type;
447 	uint16_t descriptor_length;
448 	uint8_t descriptor_data[1];
449 } __attribute__((packed));
450 
451 /** @struct pldm_vendor_defined_descriptor_title_data
452  *
453  *  Structure representing vendor defined descriptor title sections
454  */
455 struct pldm_vendor_defined_descriptor_title_data {
456 	uint8_t vendor_defined_descriptor_title_str_type;
457 	uint8_t vendor_defined_descriptor_title_str_len;
458 	uint8_t vendor_defined_descriptor_title_str[1];
459 } __attribute__((packed));
460 
461 /** @struct pldm_component_image_information
462  *
463  *  Structure representing fixed part of individual component information in
464  *  PLDM firmware update package
465  */
466 struct pldm_component_image_information {
467 	uint16_t comp_classification;
468 	uint16_t comp_identifier;
469 	uint32_t comp_comparison_stamp;
470 	bitfield16_t comp_options;
471 	bitfield16_t requested_comp_activation_method;
472 	uint32_t comp_location_offset;
473 	uint32_t comp_size;
474 	uint8_t comp_version_string_type;
475 	uint8_t comp_version_string_length;
476 } __attribute__((packed));
477 
478 /** @struct pldm_query_device_identifiers_resp
479  *
480  *  Structure representing query device identifiers response.
481  */
482 struct pldm_query_device_identifiers_resp {
483 	uint8_t completion_code;
484 	uint32_t device_identifiers_len;
485 	uint8_t descriptor_count;
486 } __attribute__((packed));
487 
488 /** @struct pldm_get_firmware_parameters_resp
489  *
490  *  Structure representing the fixed part of GetFirmwareParameters response
491  */
492 struct pldm_get_firmware_parameters_resp {
493 	uint8_t completion_code;
494 	bitfield32_t capabilities_during_update;
495 	uint16_t comp_count;
496 	uint8_t active_comp_image_set_ver_str_type;
497 	uint8_t active_comp_image_set_ver_str_len;
498 	uint8_t pending_comp_image_set_ver_str_type;
499 	uint8_t pending_comp_image_set_ver_str_len;
500 } __attribute__((packed));
501 
502 /** @struct pldm_query_downstream_devices_resp
503  *
504  *  Structure representing response of QueryDownstreamDevices.
505  *  The definition can be found Table 15 - QueryDownstreamDevices command format
506  *  in DSP0267_1.1.0
507  */
508 struct pldm_query_downstream_devices_resp {
509 	uint8_t completion_code;
510 	uint8_t downstream_device_update_supported;
511 	uint16_t number_of_downstream_devices;
512 	uint16_t max_number_of_downstream_devices;
513 	bitfield32_t capabilities;
514 };
515 
516 /** @struct pldm_component_parameter_entry
517  *
518  *  Structure representing component parameter table entry.
519  */
520 struct pldm_component_parameter_entry {
521 	uint16_t comp_classification;
522 	uint16_t comp_identifier;
523 	uint8_t comp_classification_index;
524 	uint32_t active_comp_comparison_stamp;
525 	uint8_t active_comp_ver_str_type;
526 	uint8_t active_comp_ver_str_len;
527 	uint8_t active_comp_release_date[8];
528 	uint32_t pending_comp_comparison_stamp;
529 	uint8_t pending_comp_ver_str_type;
530 	uint8_t pending_comp_ver_str_len;
531 	uint8_t pending_comp_release_date[8];
532 	bitfield16_t comp_activation_methods;
533 	bitfield32_t capabilities_during_update;
534 } __attribute__((packed));
535 
536 /** @struct pldm_query_downstream_identifiers_req
537  *
538  *  Structure for QueryDownstreamIdentifiers request defined in Table 16 -
539  *  QueryDownstreamIdentifiers command format in DSP0267_1.1.0
540  */
541 struct pldm_query_downstream_identifiers_req {
542 	uint32_t data_transfer_handle;
543 	uint8_t transfer_operation_flag;
544 };
545 
546 /** @struct pldm_query_downstream_identifiers_resp
547  *
548  *  Structure representing the fixed part of QueryDownstreamIdentifiers response
549  *  defined in Table 16 - QueryDownstreamIdentifiers command format, and
550  *  Table 17 - QueryDownstreamIdentifiers response definition in DSP0267_1.1.0.
551  *
552  *  Squash the two tables into one since the definition of
553  *  Table 17 is `Portion of QueryDownstreamIdentifiers response`
554  */
555 struct pldm_query_downstream_identifiers_resp {
556 	uint8_t completion_code;
557 	uint32_t next_data_transfer_handle;
558 	uint8_t transfer_flag;
559 	uint32_t downstream_devices_length;
560 	uint16_t number_of_downstream_devices;
561 };
562 
563 /** @struct pldm_downstream_device
564  *
565  *  Structure representing downstream device information defined in
566  *  Table 18 - DownstreamDevice definition in DSP0267_1.1.0
567  */
568 struct pldm_downstream_device {
569 	uint16_t downstream_device_index;
570 	uint8_t downstream_descriptor_count;
571 };
572 #define PLDM_DOWNSTREAM_DEVICE_BYTES 3
573 
574 struct pldm_downstream_device_iter {
575 	struct variable_field field;
576 	size_t devs;
577 };
578 
579 LIBPLDM_ITERATOR
pldm_downstream_device_iter_end(const struct pldm_downstream_device_iter * iter)580 bool pldm_downstream_device_iter_end(
581 	const struct pldm_downstream_device_iter *iter)
582 {
583 	return !iter->devs;
584 }
585 
586 LIBPLDM_ITERATOR
pldm_downstream_device_iter_next(struct pldm_downstream_device_iter * iter)587 bool pldm_downstream_device_iter_next(struct pldm_downstream_device_iter *iter)
588 {
589 	if (!iter->devs) {
590 		return false;
591 	}
592 
593 	iter->devs--;
594 	return true;
595 }
596 
597 int decode_pldm_downstream_device_from_iter(
598 	struct pldm_downstream_device_iter *iter,
599 	struct pldm_downstream_device *dev);
600 
601 /** @brief Iterate downstream devices in QueryDownstreamIdentifiers response
602  *
603  * @param devs The @ref "struct pldm_downstream_device_iter" lvalue used as the
604  *                  out-value from the corresponding call to @ref
605  *                  decode_query_downstream_identifiers_resp
606  * @param dev The @ref "struct pldm_downstream_device" lvalue into which the
607  *            next device instance should be decoded.
608  * @param rc An lvalue of type int into which the return code from the decoding
609  *           will be placed.
610  *
611  * Example use of the macro is as follows:
612  *
613  * @code
614  * struct pldm_query_downstream_identifiers_resp resp;
615  * struct pldm_downstream_device_iter devs;
616  * struct pldm_downstream_device dev;
617  * int rc;
618  *
619  * rc = decode_query_downstream_identifiers_resp(..., &resp, &devs);
620  * if (rc) {
621  *     // Handle any error from decoding fixed-portion of response
622  * }
623  *
624  * foreach_pldm_downstream_device(devs, dev, rc) {
625  *     // Do something with each decoded device placed in `dev`
626  * }
627  *
628  * if (rc) {
629  *     // Handle any decoding error while iterating variable-length set of
630  *     // devices
631  * }
632  * @endcode
633  */
634 #define foreach_pldm_downstream_device(devs, dev, rc)                          \
635 	for ((rc) = 0; (!pldm_downstream_device_iter_end(&(devs)) &&           \
636 			!((rc) = decode_pldm_downstream_device_from_iter(      \
637 				  &(devs), &(dev))));                          \
638 	     pldm_downstream_device_iter_next(&(devs)))
639 
640 /** @struct pldm_descriptor
641  *
642  * Structure representing a type-length-value descriptor as defined in Table 7 -
643  * Descriptor Definition.
644  *
645  * Member values are always host-endian. When decoding messages, the
646  * descriptor_data member points into the message buffer.
647  */
648 struct pldm_descriptor {
649 	uint16_t descriptor_type;
650 	uint16_t descriptor_length;
651 	const void *descriptor_data;
652 };
653 
654 struct pldm_descriptor_iter {
655 	struct variable_field *field;
656 	size_t count;
657 };
658 
659 LIBPLDM_ITERATOR
pldm_downstream_device_descriptor_iter_init(struct pldm_downstream_device_iter * devs,const struct pldm_downstream_device * dev)660 struct pldm_descriptor_iter pldm_downstream_device_descriptor_iter_init(
661 	struct pldm_downstream_device_iter *devs,
662 	const struct pldm_downstream_device *dev)
663 {
664 	struct pldm_descriptor_iter iter = { &devs->field,
665 					     dev->downstream_descriptor_count };
666 	return iter;
667 }
668 
669 LIBPLDM_ITERATOR
pldm_descriptor_iter_end(const struct pldm_descriptor_iter * iter)670 bool pldm_descriptor_iter_end(const struct pldm_descriptor_iter *iter)
671 {
672 	return !iter->count;
673 }
674 
675 LIBPLDM_ITERATOR
pldm_descriptor_iter_next(struct pldm_descriptor_iter * iter)676 bool pldm_descriptor_iter_next(struct pldm_descriptor_iter *iter)
677 {
678 	if (!iter->count) {
679 		return false;
680 	}
681 
682 	iter->count--;
683 	return true;
684 }
685 
686 int decode_pldm_descriptor_from_iter(struct pldm_descriptor_iter *iter,
687 				     struct pldm_descriptor *desc);
688 
689 /** @brief Iterate a downstream device's descriptors in a
690  *         QueryDownstreamIdentifiers response
691  *
692  * @param devs The @ref "struct pldm_downstream_device_iter" lvalue used as the
693  *                  out-value from the corresponding call to @ref
694  *                  decode_query_downstream_identifiers_resp
695  * @param dev The @ref "struct pldm_downstream_device" lvalue over whose
696  *            descriptors to iterate
697  * @param desc The @ref "struct pldm_descriptor" lvalue into which the next
698  *             descriptor instance should be decoded
699  * @param rc An lvalue of type int into which the return code from the decoding
700  *           will be placed
701  *
702  * Example use of the macro is as follows:
703  *
704  * @code
705  * struct pldm_query_downstream_identifiers_resp resp;
706  * struct pldm_downstream_device_iter devs;
707  * struct pldm_downstream_device dev;
708  * int rc;
709  *
710  * rc = decode_query_downstream_identifiers_resp(..., &resp, &devs);
711  * if (rc) {
712  *     // Handle any error from decoding fixed-portion of response
713  * }
714  *
715  * foreach_pldm_downstream_device(devs, dev, rc) {
716  *     struct pldm_descriptor desc;
717  *
718  *     foreach_pldm_downstream_device_descriptor(devs, dev, desc, rc) {
719  *         // Do something with each decoded descriptor placed in `desc`
720  *     }
721  *
722  *     if (rc) {
723  *         // Handle any decoding error while iterating on the variable-length
724  *         // set of descriptors
725  *     }
726  * }
727  *
728  * if (rc) {
729  *     // Handle any decoding error while iterating variable-length set of
730  *     // devices
731  * }
732  * @endcode
733  */
734 #define foreach_pldm_downstream_device_descriptor(devs, dev, desc, rc)         \
735 	for (struct pldm_descriptor_iter desc##_iter =                         \
736 		     ((rc) = 0, pldm_downstream_device_descriptor_iter_init(   \
737 					&(devs), &(dev)));                     \
738 	     (!pldm_descriptor_iter_end(&(desc##_iter)) &&                     \
739 	      !((rc) = decode_pldm_descriptor_from_iter(&(desc##_iter),        \
740 							&(desc))));            \
741 	     pldm_descriptor_iter_next(&(desc##_iter)))
742 
743 /** @struct pldm_query_downstream_firmware_param_req
744  *
745  *  Structure representing QueryDownstreamFirmwareParameters request
746  */
747 struct pldm_get_downstream_firmware_parameters_req {
748 	uint32_t data_transfer_handle;
749 	uint8_t transfer_operation_flag;
750 };
751 
752 /** @struct pldm_get_downstream_firmware_parameters_resp
753  *
754  *  Structure representing the fixed part of QueryDownstreamFirmwareParameters
755  *  response in Table 19 - GetDownstreamFirmwareParameters command format, and
756  *  Table 20 - QueryDownstreamFirmwareParameters response definition in
757  *  DSP0267_1.1.0.
758  *
759  *  Squash the two tables into one since the definition of Table 20 is `Portion
760  *  of GetDownstreamFirmwareParameters response`
761  */
762 struct pldm_get_downstream_firmware_parameters_resp {
763 	uint8_t completion_code;
764 	uint32_t next_data_transfer_handle;
765 	uint8_t transfer_flag;
766 	bitfield32_t fdp_capabilities_during_update;
767 	uint16_t downstream_device_count;
768 };
769 
770 /** @struct pldm_downstream_device_parameters_entry
771  *
772  *  Structure representing downstream device parameter table entry defined in
773  *  Table 21 - DownstreamDeviceParameterTable in DSP0267_1.1.0
774  *
775  *  Clients should not allocate memory for this struct to decode the response,
776  *  use `pldm_downstream_device_parameter_entry_versions` instead to make sure
777  *  that the active and pending component version strings are copied from the
778  *  message buffer.
779  */
780 struct pldm_downstream_device_parameters_entry {
781 	uint16_t downstream_device_index;
782 	uint32_t active_comp_comparison_stamp;
783 	uint8_t active_comp_ver_str_type;
784 	uint8_t active_comp_ver_str_len;
785 	/* Append 1 bytes for null termination so that it can be used as a
786 	 * Null-terminated string.
787 	 */
788 	char active_comp_release_date[PLDM_FWUP_COMPONENT_RELEASE_DATA_LEN + 1];
789 	uint32_t pending_comp_comparison_stamp;
790 	uint8_t pending_comp_ver_str_type;
791 	uint8_t pending_comp_ver_str_len;
792 	/* Append 1 bytes for null termination so that it can be used as a
793 	 * Null-terminated string.
794 	 */
795 	char pending_comp_release_date[PLDM_FWUP_COMPONENT_RELEASE_DATA_LEN + 1];
796 	bitfield16_t comp_activation_methods;
797 	bitfield32_t capabilities_during_update;
798 	const void *active_comp_ver_str;
799 	const void *pending_comp_ver_str;
800 };
801 
802 /** @struct pldm_request_update_req
803  *
804  *  Structure representing fixed part of Request Update request
805  */
806 struct pldm_request_update_req {
807 	uint32_t max_transfer_size;
808 	uint16_t num_of_comp;
809 	uint8_t max_outstanding_transfer_req;
810 	uint16_t pkg_data_len;
811 	uint8_t comp_image_set_ver_str_type;
812 	uint8_t comp_image_set_ver_str_len;
813 } __attribute__((packed));
814 
815 /** @struct pldm_request_update_resp
816  *
817  *  Structure representing Request Update response
818  */
819 struct pldm_request_update_resp {
820 	uint8_t completion_code;
821 	uint16_t fd_meta_data_len;
822 	uint8_t fd_will_send_pkg_data;
823 } __attribute__((packed));
824 
825 /** @struct pldm_pass_component_table_req
826  *
827  *  Structure representing PassComponentTable request
828  */
829 struct pldm_pass_component_table_req {
830 	uint8_t transfer_flag;
831 	uint16_t comp_classification;
832 	uint16_t comp_identifier;
833 	uint8_t comp_classification_index;
834 	uint32_t comp_comparison_stamp;
835 	uint8_t comp_ver_str_type;
836 	uint8_t comp_ver_str_len;
837 } __attribute__((packed));
838 
839 /** @struct pldm_pass_component_table_resp
840  *
841  *  Structure representing PassComponentTable response
842  */
843 struct pldm_pass_component_table_resp {
844 	uint8_t completion_code;
845 	uint8_t comp_resp;
846 	uint8_t comp_resp_code;
847 } __attribute__((packed));
848 
849 /** @struct pldm_update_component_req
850  *
851  *  Structure representing UpdateComponent request
852  */
853 struct pldm_update_component_req {
854 	uint16_t comp_classification;
855 	uint16_t comp_identifier;
856 	uint8_t comp_classification_index;
857 	uint32_t comp_comparison_stamp;
858 	uint32_t comp_image_size;
859 	bitfield32_t update_option_flags;
860 	uint8_t comp_ver_str_type;
861 	uint8_t comp_ver_str_len;
862 } __attribute__((packed));
863 
864 /** @struct pldm_update_component_resp
865  *
866  *  Structure representing UpdateComponent response
867  */
868 struct pldm_update_component_resp {
869 	uint8_t completion_code;
870 	uint8_t comp_compatibility_resp;
871 	uint8_t comp_compatibility_resp_code;
872 	bitfield32_t update_option_flags_enabled;
873 	uint16_t time_before_req_fw_data;
874 } __attribute__((packed));
875 
876 /** @struct pldm_request_firmware_data_req
877  *
878  *  Structure representing RequestFirmwareData request.
879  */
880 struct pldm_request_firmware_data_req {
881 	uint32_t offset;
882 	uint32_t length;
883 } __attribute__((packed));
884 
885 /** @struct pldm_apply_complete_req
886  *
887  *  Structure representing ApplyComplete request.
888  */
889 struct pldm_apply_complete_req {
890 	uint8_t apply_result;
891 	bitfield16_t comp_activation_methods_modification;
892 } __attribute__((packed));
893 
894 /** @struct pldm_activate_firmware_req
895  *
896  *  Structure representing ActivateFirmware request
897  */
898 struct pldm_activate_firmware_req {
899 	bool8_t self_contained_activation_req;
900 } __attribute__((packed));
901 
902 /** @struct activate_firmware_resp
903  *
904  *  Structure representing Activate Firmware response
905  */
906 struct pldm_activate_firmware_resp {
907 	uint8_t completion_code;
908 	uint16_t estimated_time_activation;
909 } __attribute__((packed));
910 
911 /** @struct pldm_get_status_resp
912  *
913  *  Structure representing GetStatus response.
914  */
915 struct pldm_get_status_resp {
916 	uint8_t completion_code;
917 	uint8_t current_state;
918 	uint8_t previous_state;
919 	uint8_t aux_state;
920 	uint8_t aux_state_status;
921 	uint8_t progress_percent;
922 	uint8_t reason_code;
923 	bitfield32_t update_option_flags_enabled;
924 } __attribute__((packed));
925 
926 /** @struct pldm_cancel_update_resp
927  *
928  *  Structure representing CancelUpdate response.
929  */
930 struct pldm_cancel_update_resp {
931 	uint8_t completion_code;
932 	bool8_t non_functioning_component_indication;
933 	uint64_t non_functioning_component_bitmap;
934 } __attribute__((packed));
935 
936 /** @brief Decode the PLDM package header information
937  *
938  *  @param[in] data - pointer to package header information
939  *  @param[in] length - available length in the firmware update package
940  *  @param[out] package_header_info - pointer to fixed part of PLDM package
941  *                                    header information
942  *  @param[out] package_version_str - pointer to package version string
943  *
944  *  @return pldm_completion_codes
945  */
946 int decode_pldm_package_header_info(
947 	const uint8_t *data, size_t length,
948 	struct pldm_package_header_information *package_header_info,
949 	struct variable_field *package_version_str);
950 
951 /** @brief Decode individual firmware device ID record
952  *
953  *  @param[in] data - pointer to firmware device ID record
954  *  @param[in] length - available length in the firmware update package
955  *  @param[in] component_bitmap_bit_length - ComponentBitmapBitLengthfield
956  *                                           parsed from the package header info
957  *  @param[out] fw_device_id_record - pointer to fixed part of firmware device
958  *                                    id record
959  *  @param[out] applicable_components - pointer to ApplicableComponents
960  *  @param[out] comp_image_set_version_str - pointer to
961  *                                           ComponentImageSetVersionString
962  *  @param[out] record_descriptors - pointer to RecordDescriptors
963  *  @param[out] fw_device_pkg_data - pointer to FirmwareDevicePackageData
964  *
965  *  @return pldm_completion_codes
966  */
967 int decode_firmware_device_id_record(
968 	const uint8_t *data, size_t length,
969 	uint16_t component_bitmap_bit_length,
970 	struct pldm_firmware_device_id_record *fw_device_id_record,
971 	struct variable_field *applicable_components,
972 	struct variable_field *comp_image_set_version_str,
973 	struct variable_field *record_descriptors,
974 	struct variable_field *fw_device_pkg_data);
975 
976 /** @brief Decode the record descriptor entries in the firmware update package
977  *         and the Descriptors in the QueryDeviceIDentifiers command
978  *
979  *  @param[in] data - pointer to descriptor entry
980  *  @param[in] length - remaining length of the descriptor data
981  *  @param[out] descriptor_type - pointer to descriptor type
982  *  @param[out] descriptor_data - pointer to descriptor data
983  *
984  *  @return pldm_completion_codes
985  */
986 int decode_descriptor_type_length_value(const uint8_t *data, size_t length,
987 					uint16_t *descriptor_type,
988 					struct variable_field *descriptor_data);
989 
990 /** @brief Decode the vendor defined descriptor value
991  *
992  *  @param[in] data - pointer to vendor defined descriptor value
993  *  @param[in] length - length of the vendor defined descriptor value
994  *  @param[out] descriptor_title_str_type - pointer to vendor defined descriptor
995  *                                          title string type
996  *  @param[out] descriptor_title_str - pointer to vendor defined descriptor
997  *                                     title string
998  *  @param[out] descriptor_data - pointer to vendor defined descriptor data
999  *
1000  *  @return pldm_completion_codes
1001  */
1002 int decode_vendor_defined_descriptor_value(
1003 	const uint8_t *data, size_t length, uint8_t *descriptor_title_str_type,
1004 	struct variable_field *descriptor_title_str,
1005 	struct variable_field *descriptor_data);
1006 
1007 /** @brief Decode individual component image information
1008  *
1009  *  @param[in] data - pointer to component image information
1010  *  @param[in] length - available length in the firmware update package
1011  *  @param[out] pldm_comp_image_info - pointer to fixed part of component image
1012  *                                     information
1013  *  @param[out] comp_version_str - pointer to component version string
1014  *
1015  *  @return pldm_completion_codes
1016  */
1017 int decode_pldm_comp_image_info(
1018 	const uint8_t *data, size_t length,
1019 	struct pldm_component_image_information *pldm_comp_image_info,
1020 	struct variable_field *comp_version_str);
1021 
1022 /** @brief Create a PLDM request message for QueryDeviceIdentifiers
1023  *
1024  *  @param[in] instance_id - Message's instance id
1025  *  @param[in] payload_length - Length of the request message payload
1026  *  @param[in,out] msg - Message will be written to this
1027  *
1028  *  @return pldm_completion_codes
1029  *
1030  *  @note  Caller is responsible for memory alloc and dealloc of param
1031  *         'msg.payload'
1032  */
1033 int encode_query_device_identifiers_req(uint8_t instance_id,
1034 					size_t payload_length,
1035 					struct pldm_msg *msg);
1036 
1037 /** @brief Decode QueryDeviceIdentifiers response message
1038  *
1039  *  @param[in] msg - Response message
1040  *  @param[in] payload_length - Length of response message payload
1041  *  @param[out] completion_code - Pointer to response msg's PLDM completion code
1042  *  @param[out] device_identifiers_len - Pointer to device identifiers length
1043  *  @param[out] descriptor_count - Pointer to descriptor count
1044  *  @param[out] descriptor_data - Pointer to descriptor data
1045  *
1046  *  @return pldm_completion_codes
1047  */
1048 int decode_query_device_identifiers_resp(const struct pldm_msg *msg,
1049 					 size_t payload_length,
1050 					 uint8_t *completion_code,
1051 					 uint32_t *device_identifiers_len,
1052 					 uint8_t *descriptor_count,
1053 					 uint8_t **descriptor_data);
1054 
1055 /** @brief Create a PLDM request message for GetFirmwareParameters
1056  *
1057  *  @param[in] instance_id - Message's instance id
1058  *  @param[in] payload_length - Length of the request message payload
1059  *  @param[in,out] msg - Message will be written to this
1060  *
1061  *  @return pldm_completion_codes
1062  *
1063  *  @note  Caller is responsible for memory alloc and dealloc of param
1064  *         'msg.payload'
1065  */
1066 int encode_get_firmware_parameters_req(uint8_t instance_id,
1067 				       size_t payload_length,
1068 				       struct pldm_msg *msg);
1069 
1070 /** @brief Decode GetFirmwareParameters response
1071  *
1072  *  @param[in] msg - Response message
1073  *  @param[in] payload_length - Length of response message payload
1074  *  @param[out] resp_data - Pointer to get firmware parameters response
1075  *  @param[out] active_comp_image_set_ver_str - Pointer to active component
1076  *                                              image set version string
1077  *  @param[out] pending_comp_image_set_ver_str - Pointer to pending component
1078  *                                               image set version string
1079  *  @param[out] comp_parameter_table - Pointer to component parameter table
1080  *
1081  *  @return pldm_completion_codes
1082  */
1083 int decode_get_firmware_parameters_resp(
1084 	const struct pldm_msg *msg, size_t payload_length,
1085 	struct pldm_get_firmware_parameters_resp *resp_data,
1086 	struct variable_field *active_comp_image_set_ver_str,
1087 	struct variable_field *pending_comp_image_set_ver_str,
1088 	struct variable_field *comp_parameter_table);
1089 
1090 /** @brief Decode component entries in the component parameter table which is
1091  *         part of the response of GetFirmwareParameters command
1092  *
1093  *  @param[in] data - Component entry
1094  *  @param[in] length - Length of component entry
1095  *  @param[out] component_data - Pointer to component parameter table
1096  *  @param[out] active_comp_ver_str - Pointer to active component version string
1097  *  @param[out] pending_comp_ver_str - Pointer to pending component version
1098  *                                     string
1099  *
1100  *  @return pldm_completion_codes
1101  */
1102 int decode_get_firmware_parameters_resp_comp_entry(
1103 	const uint8_t *data, size_t length,
1104 	struct pldm_component_parameter_entry *component_data,
1105 	struct variable_field *active_comp_ver_str,
1106 	struct variable_field *pending_comp_ver_str);
1107 
1108 /** @brief Create a PLDM request message for QueryDownstreamDevices
1109  *
1110  *  @param[in] instance_id - Message's instance id
1111  *  @param[out] msg - Message will be written to this
1112  *
1113  *  @return 0 on success, otherwise -EINVAL if the input parameters' memory
1114  *          are not allocated, -EOVERFLOW if the payload length is not enough
1115  *          to encode the message, -EBADMSG if the message is not valid.
1116  *
1117  *  @note  Caller is responsible for memory alloc and dealloc of param
1118  *         'msg.payload'
1119  */
1120 int encode_query_downstream_devices_req(uint8_t instance_id,
1121 					struct pldm_msg *msg);
1122 
1123 /**
1124  * @brief Decodes the response message for Querying Downstream Devices.
1125  *
1126  * @param[in] msg The PLDM message to decode.
1127  * @param[in] payload_length The length of the message payload.
1128  * @param[out] resp_data Pointer to the structure to store the decoded response data.
1129  * @return 0 on success, otherwise -EINVAL if the input parameters' memory
1130  *         are not allocated, -EOVERFLOW if the payload length is not enough
1131  *         to decode the message, -EBADMSG if the message is not valid.
1132  *
1133  * @note  Caller is responsible for memory alloc and dealloc of param
1134  *         'msg.payload'
1135  */
1136 int decode_query_downstream_devices_resp(
1137 	const struct pldm_msg *msg, size_t payload_length,
1138 	struct pldm_query_downstream_devices_resp *resp_data);
1139 
1140 /**
1141  * @brief Encodes a request message for Query Downstream Identifiers.
1142  *
1143  * @param[in] instance_id The instance ID of the PLDM entity.
1144  * @param[in] data_transfer_handle The handle for the data transfer.
1145  * @param[in] transfer_operation_flag The flag indicating the transfer operation.
1146  * @param[out] msg Pointer to the PLDM message structure to store the encoded message.
1147  * @param[in] payload_length The length of the payload.
1148  * @return 0 on success, otherwise -EINVAL if the input parameters' memory
1149  *         are not allocated, -EOVERFLOW if the payload length is not enough
1150  *         to encode the message, -EBADMSG if the message is not valid.
1151  *
1152  * @note Caller is responsible for memory alloc and dealloc of param
1153  *        'msg.payload'
1154  */
1155 int encode_query_downstream_identifiers_req(
1156 	uint8_t instance_id,
1157 	const struct pldm_query_downstream_identifiers_req *params_req,
1158 	struct pldm_msg *msg, size_t payload_length);
1159 
1160 /**
1161  * @brief Decodes the response message for Querying Downstream Identifiers.
1162  * @param[in] msg The PLDM message to decode.
1163  * @param[in] payload_length The length of the message payload.
1164  * @param[out] resp_data Pointer to the decoded response data.
1165  * @param[out] iter Pointer to the downstream device iterator structure.
1166  * @return 0 on success, otherwise -EINVAL if the input parameters' memory
1167  *         are not allocated, -EOVERFLOW if the payload length is not enough
1168  *         to decode the message, -EBADMSG if the message is not valid.
1169  *
1170  * @note Caller is responsible for memory alloc and dealloc of pointer params
1171  */
1172 int decode_query_downstream_identifiers_resp(
1173 	const struct pldm_msg *msg, size_t payload_length,
1174 	struct pldm_query_downstream_identifiers_resp *resp_data,
1175 	struct pldm_downstream_device_iter *iter);
1176 
1177 /**
1178  * @brief Encodes request message for Get Downstream Firmware Parameters.
1179  *
1180  * @param[in] instance_id - The instance ID of the PLDM entity.
1181  * @param[in] data_transfer_handle - The handle for the data transfer.
1182  * @param[in] transfer_operation_flag - The flag indicating the transfer operation.
1183  * @param[in,out] msg - A pointer to the PLDM message structure to store the encoded message.
1184  * @param[in] payload_length - The length of the payload.
1185  *
1186  * @return 0 on success, otherwise -EINVAL if the input parameters' memory
1187  *         are not allocated, -EOVERFLOW if the payload length is not enough
1188  *         to encode the message, -EBADMSG if the message is not valid.
1189  *
1190  * @note Caller is responsible for memory alloc and dealloc of param
1191  *        'msg.payload'
1192  */
1193 int encode_get_downstream_firmware_parameters_req(
1194 	uint8_t instance_id,
1195 	const struct pldm_get_downstream_firmware_parameters_req *params_req,
1196 	struct pldm_msg *msg, size_t payload_length);
1197 
1198 struct pldm_downstream_device_parameters_iter {
1199 	struct variable_field field;
1200 	size_t entries;
1201 };
1202 
1203 /**
1204  * @brief Decode response message for Get Downstream Firmware Parameters
1205  *
1206  * @param[in] msg - The PLDM message to decode
1207  * @param[in] payload_length - The length of the message payload
1208  * @param[out] resp_data - Pointer to the structure to store the decoded response data
1209  * @param[out] downstream_device_param_table - Pointer to the variable field structure
1210  *                                           to store the decoded downstream device
1211  *                                           parameter table
1212  * @return 0 on success, otherwise -EINVAL if the input parameters' memory
1213  *         are not allocated, -EOVERFLOW if the payload length is not enough
1214  *         to decode the message, -EBADMSG if the message is not valid.
1215  *
1216  * @note Caller is responsible for memory alloc and dealloc of param
1217  *        'resp_data' and 'downstream_device_param_table'
1218  */
1219 int decode_get_downstream_firmware_parameters_resp(
1220 	const struct pldm_msg *msg, size_t payload_length,
1221 	struct pldm_get_downstream_firmware_parameters_resp *resp_data,
1222 	struct pldm_downstream_device_parameters_iter *iter);
1223 
1224 /**
1225  * @brief Decode the next downstream device parameter table entry
1226  *
1227  * @param[in,out] data - A variable field covering the table entries in the
1228  *                       response message data. @p data is updated to point to
1229  *                       the remaining entries once the current entry has been
1230  *                       decoded.
1231 
1232  * @param[out] entry - The struct object into which the current table entry will
1233  *                     be decoded
1234 
1235  * @param[out] versions - A variable field covering the active and
1236  *                        pending component version strings in the
1237  *                        response message data. The component version
1238  *                        strings can be decoded into @p entry using
1239  *                        decode_downstream_device_parameter_table_entry_versions()
1240  *
1241  * @return 0 on success, otherwise -EINVAL if the input parameters' memory
1242  *         are not allocated, -EOVERFLOW if the payload length is not enough
1243  *         to decode the entry.
1244  *
1245  * @note Caller is responsible for memory alloc and dealloc of param
1246  * 	  'entry', 'active_comp_ver_str' and 'pending_comp_ver_str'
1247  */
1248 int decode_pldm_downstream_device_parameters_entry_from_iter(
1249 	struct pldm_downstream_device_parameters_iter *iter,
1250 	struct pldm_downstream_device_parameters_entry *entry);
1251 
1252 LIBPLDM_ITERATOR
pldm_downstream_device_parameters_iter_end(const struct pldm_downstream_device_parameters_iter * iter)1253 bool pldm_downstream_device_parameters_iter_end(
1254 	const struct pldm_downstream_device_parameters_iter *iter)
1255 {
1256 	return !iter->entries;
1257 }
1258 
1259 LIBPLDM_ITERATOR
pldm_downstream_device_parameters_iter_next(struct pldm_downstream_device_parameters_iter * iter)1260 bool pldm_downstream_device_parameters_iter_next(
1261 	struct pldm_downstream_device_parameters_iter *iter)
1262 {
1263 	if (!iter->entries) {
1264 		return false;
1265 	}
1266 
1267 	iter->entries--;
1268 	return true;
1269 }
1270 
1271 /** @brief Iterator downstream device parameter entries in Get Downstream
1272  *         Firmware Parameters response
1273  *
1274  * @param params The @ref "struct pldm_downstream_device_parameters_iter" lvalue
1275  *               used as the out-value from the corresponding call to @ref
1276  *               decode_get_downstream_firmware_parameters_resp
1277  * @param entry The @ref "struct pldm_downstream_device_parameters_entry" lvalue
1278  *              into which the next parameter table entry should be decoded
1279  * @param rc An lvalue of type int into which the return code from the decoding
1280  *           will be placed
1281  *
1282  * Example use of the macro is as follows:
1283  *
1284  * @code
1285  * struct pldm_get_downstream_firmware_parameters_resp resp;
1286  * struct pldm_downstream_device_parameters_iter params;
1287  * struct pldm_downstream_device_parameters_entry entry;
1288  * int rc;
1289  *
1290  * rc = decode_get_downstream_firmware_parameters_resp(..., &resp, &params);
1291  * if (rc) {
1292  *     // Handle any error from decoding the fixed-portion of response
1293  * }
1294  *
1295  * foreach_pldm_downstream_device_parameters_entry(params, entry, rc) {
1296  *     // Do something with the decoded entry
1297  * }
1298  *
1299  * if (rc) {
1300  *     // Handle any decoding error while iterating the variable-length set of
1301  *     //parameter entries
1302  * }
1303  * @endcode
1304  */
1305 #define foreach_pldm_downstream_device_parameters_entry(params, entry, rc)       \
1306 	for ((rc) = 0;                                                           \
1307 	     (!pldm_downstream_device_parameters_iter_end(&(params)) &&          \
1308 	      !((rc) = decode_pldm_downstream_device_parameters_entry_from_iter( \
1309 			&(params), &(entry))));                                  \
1310 	     pldm_downstream_device_parameters_iter_next(&(params)))
1311 
1312 /** @brief Create PLDM request message for RequestUpdate
1313  *
1314  *  @param[in] instance_id - Message's instance id
1315  *  @param[in] max_transfer_size - Maximum size of the variable payload allowed
1316  *                                 to be requested via RequestFirmwareData
1317  *                                 command
1318  *  @param[in] num_of_comp - Total number of components that will be passed to
1319  *                           the FD during the update
1320  *  @param[in] max_outstanding_transfer_req - Total number of outstanding
1321  * 											  RequestFirmwareData
1322  * commands that can be sent by the FD
1323  *  @param[in] pkg_data_len - Value of the FirmwareDevicePackageDataLength field
1324  *                            present in firmware package header
1325  *  @param[in] comp_image_set_ver_str_type - StringType of
1326  *                                           ComponentImageSetVersionString
1327  *  @param[in] comp_image_set_ver_str_len - The length of the
1328  *                                          ComponentImageSetVersionString
1329  *  @param[in] comp_img_set_ver_str - Component Image Set version information
1330  *  @param[in,out] msg - Message will be written to this
1331  *  @param[in] payload_length - Length of request message payload
1332  *
1333  *  @return pldm_completion_codes
1334  *
1335  *  @note Caller is responsible for memory alloc and dealloc of param
1336  *        'msg.payload'
1337  */
1338 int encode_request_update_req(uint8_t instance_id, uint32_t max_transfer_size,
1339 			      uint16_t num_of_comp,
1340 			      uint8_t max_outstanding_transfer_req,
1341 			      uint16_t pkg_data_len,
1342 			      uint8_t comp_image_set_ver_str_type,
1343 			      uint8_t comp_image_set_ver_str_len,
1344 			      const struct variable_field *comp_img_set_ver_str,
1345 			      struct pldm_msg *msg, size_t payload_length);
1346 
1347 /** @brief Decode a RequestUpdate response message
1348  *
1349  *  @param[in] msg - Response message
1350  *  @param[in] payload_length - Length of response message payload
1351  *  @param[out] completion_code - Pointer to hold the completion code
1352  *  @param[out] fd_meta_data_len - Pointer to hold the length of FD metadata
1353  *  @param[out] fd_will_send_pkg_data - Pointer to hold information whether FD
1354  *                                      will send GetPackageData command
1355  *  @return pldm_completion_codes
1356  */
1357 int decode_request_update_resp(const struct pldm_msg *msg,
1358 			       size_t payload_length, uint8_t *completion_code,
1359 			       uint16_t *fd_meta_data_len,
1360 			       uint8_t *fd_will_send_pkg_data);
1361 
1362 /** @brief Create PLDM request message for PassComponentTable
1363  *
1364  *  @param[in] instance_id - Message's instance id
1365  *  @param[in] transfer_flag - TransferFlag
1366  *  @param[in] comp_classification - ComponentClassification
1367  *  @param[in] comp_identifier - ComponentIdentifier
1368  *  @param[in] comp_classification_index - ComponentClassificationIndex
1369  *  @param[in] comp_comparison_stamp - ComponentComparisonStamp
1370  *  @param[in] comp_ver_str_type - ComponentVersionStringType
1371  *  @param[in] comp_ver_str_len - ComponentVersionStringLength
1372  *  @param[in] comp_ver_str - ComponentVersionString
1373  *  @param[in,out] msg - Message will be written to this
1374  *  @param[in] payload_length - Length of request message payload
1375  *                              information
1376  *
1377  *  @return pldm_completion_codes
1378  *
1379  *  @note  Caller is responsible for memory alloc and dealloc of param
1380  *         'msg.payload'
1381  */
1382 int encode_pass_component_table_req(
1383 	uint8_t instance_id, uint8_t transfer_flag,
1384 	uint16_t comp_classification, uint16_t comp_identifier,
1385 	uint8_t comp_classification_index, uint32_t comp_comparison_stamp,
1386 	uint8_t comp_ver_str_type, uint8_t comp_ver_str_len,
1387 	const struct variable_field *comp_ver_str, struct pldm_msg *msg,
1388 	size_t payload_length);
1389 
1390 /** @brief Decode PassComponentTable response message
1391  *
1392  *  @param[in] msg - Response message
1393  *  @param[in] payload_length - Length of response message payload
1394  *  @param[out] completion_code - Pointer to hold completion code
1395  *  @param[out] comp_resp - Pointer to hold component response
1396  *  @param[out] comp_resp_code - Pointer to hold component response code
1397  *
1398  *  @return pldm_completion_codes
1399  */
1400 int decode_pass_component_table_resp(const struct pldm_msg *msg,
1401 				     size_t payload_length,
1402 				     uint8_t *completion_code,
1403 				     uint8_t *comp_resp,
1404 				     uint8_t *comp_resp_code);
1405 
1406 /** @brief Create PLDM request message for UpdateComponent
1407  *
1408  *  @param[in] instance_id - Message's instance id
1409  *  @param[in] comp_classification - ComponentClassification
1410  *  @param[in] comp_identifier - ComponentIdentifier
1411  *  @param[in] comp_classification_index - ComponentClassificationIndex
1412  *  @param[in] comp_comparison_stamp - ComponentComparisonStamp
1413  *  @param[in] comp_image_size - ComponentImageSize
1414  *  @param[in] update_option_flags - UpdateOptionFlags
1415  *  @param[in] comp_ver_str_type - ComponentVersionStringType
1416  *  @param[in] comp_ver_str_len - ComponentVersionStringLength
1417  *  @param[in] comp_ver_str - ComponentVersionString
1418  *  @param[in,out] msg - Message will be written to this
1419  *  @param[in] payload_length - Length of request message payload
1420  *                              information
1421  *
1422  *  @return pldm_completion_codes
1423  *
1424  *  @note  Caller is responsible for memory alloc and dealloc of param
1425  *         'msg.payload'
1426  */
1427 int encode_update_component_req(
1428 	uint8_t instance_id, uint16_t comp_classification,
1429 	uint16_t comp_identifier, uint8_t comp_classification_index,
1430 	uint32_t comp_comparison_stamp, uint32_t comp_image_size,
1431 	bitfield32_t update_option_flags, uint8_t comp_ver_str_type,
1432 	uint8_t comp_ver_str_len, const struct variable_field *comp_ver_str,
1433 	struct pldm_msg *msg, size_t payload_length);
1434 
1435 /** @brief Decode UpdateComponent response message
1436  *
1437  *  @param[in] msg - Response message
1438  *  @param[in] payload_length - Length of response message payload
1439  *  @param[out] completion_code - Pointer to hold completion code
1440  *  @param[out] comp_compatibility_resp - Pointer to hold component
1441  *                                        compatibility response
1442  *  @param[out] comp_compatibility_resp_code - Pointer to hold component
1443  *                                             compatibility response code
1444  *  @param[out] update_option_flags_enabled - Pointer to hold
1445  *                                            UpdateOptionsFlagEnabled
1446  *  @param[out] time_before_req_fw_data - Pointer to hold the estimated time
1447  *                                        before sending RequestFirmwareData
1448  *
1449  *  @return pldm_completion_codes
1450  */
1451 int decode_update_component_resp(const struct pldm_msg *msg,
1452 				 size_t payload_length,
1453 				 uint8_t *completion_code,
1454 				 uint8_t *comp_compatibility_resp,
1455 				 uint8_t *comp_compatibility_resp_code,
1456 				 bitfield32_t *update_option_flags_enabled,
1457 				 uint16_t *time_before_req_fw_data);
1458 
1459 /** @brief Decode RequestFirmwareData request message
1460  *
1461  *	@param[in] msg - Request message
1462  *	@param[in] payload_length - Length of request message payload
1463  *	@param[out] offset - Pointer to hold offset
1464  *	@param[out] length - Pointer to hold the size of the component image
1465  *                       segment requested by the FD/FDP
1466  *
1467  *	@return pldm_completion_codes
1468  */
1469 int decode_request_firmware_data_req(const struct pldm_msg *msg,
1470 				     size_t payload_length, uint32_t *offset,
1471 				     uint32_t *length);
1472 
1473 /** @brief Create PLDM response message for RequestFirmwareData
1474  *
1475  *  The ComponentImagePortion is not encoded in the PLDM response message
1476  *  by encode_request_firmware_data_resp to avoid an additional copy. Populating
1477  *  ComponentImagePortion in the PLDM response message is handled by the user
1478  *  of this API. The payload_length validation considers only the
1479  *  CompletionCode.
1480  *
1481  *	@param[in] instance_id - Message's instance id
1482  *	@param[in] completion_code - CompletionCode
1483  *	@param[in,out] msg - Message will be written to this
1484  *  @param[in] payload_length - Length of response message payload
1485  *
1486  *	@return pldm_completion_codes
1487  *
1488  *	@note  Caller is responsible for memory alloc and dealloc of param
1489  *		   'msg.payload'
1490  */
1491 int encode_request_firmware_data_resp(uint8_t instance_id,
1492 				      uint8_t completion_code,
1493 				      struct pldm_msg *msg,
1494 				      size_t payload_length);
1495 
1496 /** @brief Decode TransferComplete request message
1497  *
1498  *  @param[in] msg - Request message
1499  *  @param[in] payload_length - Length of request message payload
1500  *  @param[out] transfer_result - Pointer to hold TransferResult
1501  *
1502  *  @return pldm_completion_codes
1503  */
1504 int decode_transfer_complete_req(const struct pldm_msg *msg,
1505 				 size_t payload_length,
1506 				 uint8_t *transfer_result);
1507 
1508 /** @brief Create PLDM response message for TransferComplete
1509  *
1510  *  @param[in] instance_id - Message's instance id
1511  *  @param[in] completion_code - CompletionCode
1512  *  @param[in,out] msg - Message will be written to this
1513  *  @param[in] payload_length - Length of response message payload
1514  *
1515  *  @return pldm_completion_codes
1516  *
1517  *  @note  Caller is responsible for memory alloc and dealloc of param
1518  *         'msg.payload'
1519  */
1520 int encode_transfer_complete_resp(uint8_t instance_id, uint8_t completion_code,
1521 				  struct pldm_msg *msg, size_t payload_length);
1522 
1523 /** @brief Decode VerifyComplete request message
1524  *
1525  *  @param[in] msg - Request message
1526  *  @param[in] payload_length - Length of request message payload
1527  *  @param[in] verify_result - Pointer to hold VerifyResult
1528  *
1529  *  @return pldm_completion_codes
1530  */
1531 int decode_verify_complete_req(const struct pldm_msg *msg,
1532 			       size_t payload_length, uint8_t *verify_result);
1533 
1534 /** @brief Create PLDM response message for VerifyComplete
1535  *
1536  *  @param[in] instance_id - Message's instance id
1537  *  @param[in] completion_code - CompletionCode
1538  *  @param[in,out] msg - Message will be written to this
1539  *  @param[in] payload_length - Length of response message payload
1540  *
1541  *  @return pldm_completion_codes
1542  *
1543  *  @note  Caller is responsible for memory alloc and dealloc of param
1544  *         'msg.payload'
1545  */
1546 int encode_verify_complete_resp(uint8_t instance_id, uint8_t completion_code,
1547 				struct pldm_msg *msg, size_t payload_length);
1548 
1549 /** @brief Decode ApplyComplete request message
1550  *
1551  *  @param[in] msg - Request message
1552  *  @param[in] payload_length - Length of request message payload
1553  *  @param[in] apply_result - Pointer to hold ApplyResult
1554  *  @param[in] comp_activation_methods_modification - Pointer to hold the
1555  *                                        ComponentActivationMethodsModification
1556  *
1557  *  @return pldm_completion_codes
1558  */
1559 int decode_apply_complete_req(
1560 	const struct pldm_msg *msg, size_t payload_length,
1561 	uint8_t *apply_result,
1562 	bitfield16_t *comp_activation_methods_modification);
1563 
1564 /** @brief Create PLDM response message for ApplyComplete
1565  *
1566  *  @param[in] instance_id - Message's instance id
1567  *  @param[in] completion_code - CompletionCode
1568  *  @param[in,out] msg - Message will be written to this
1569  *  @param[in] payload_length - Length of response message payload
1570  *
1571  *  @return pldm_completion_codes
1572  *
1573  *  @note Caller is responsible for memory alloc and dealloc of param
1574  *        'msg.payload'
1575  */
1576 int encode_apply_complete_resp(uint8_t instance_id, uint8_t completion_code,
1577 			       struct pldm_msg *msg, size_t payload_length);
1578 
1579 /** @brief Create PLDM request message for ActivateFirmware
1580  *
1581  *  @param[in] instance_id - Message's instance id
1582  *  @param[in] self_contained_activation_req SelfContainedActivationRequest
1583  *  @param[in,out] msg - Message will be written to this
1584  *  @param[in] payload_length - Length of request message payload
1585  *
1586  *  @return pldm_completion_codes
1587  *
1588  *  @note  Caller is responsible for memory alloc and dealloc of param
1589  *         'msg.payload'
1590  */
1591 int encode_activate_firmware_req(uint8_t instance_id,
1592 				 bool8_t self_contained_activation_req,
1593 				 struct pldm_msg *msg, size_t payload_length);
1594 
1595 /** @brief Decode ActivateFirmware response message
1596  *
1597  *  @param[in] msg - Response message
1598  *  @param[in] payload_length - Length of response message payload
1599  *  @param[out] completion_code - Pointer to hold CompletionCode
1600  *  @param[out] estimated_time_activation - Pointer to hold
1601  *                                       EstimatedTimeForSelfContainedActivation
1602  *
1603  *  @return pldm_completion_codes
1604  */
1605 int decode_activate_firmware_resp(const struct pldm_msg *msg,
1606 				  size_t payload_length,
1607 				  uint8_t *completion_code,
1608 				  uint16_t *estimated_time_activation);
1609 
1610 /** @brief Create PLDM request message for GetStatus
1611  *
1612  *  @param[in] instance_id - Message's instance id
1613  *  @param[in,out] msg - Message will be written to this
1614  *  @param[in] payload_length - Length of request message payload
1615  *
1616  *  @return pldm_completion_codes
1617  *
1618  *  @note Caller is responsible for memory alloc and dealloc of param
1619  *        'msg.payload'
1620  */
1621 int encode_get_status_req(uint8_t instance_id, struct pldm_msg *msg,
1622 			  size_t payload_length);
1623 
1624 /** @brief Decode GetStatus response message
1625  *
1626  *  @param[in] msg - Response message
1627  *  @param[in] payload_length - Length of response message payload
1628  *  @param[out] completion_code - Pointer to completion code
1629  *  @param[out] current_state - Pointer to current state machine state
1630  *  @param[out] previous_state - Pointer to previous different state machine
1631  *                               state
1632  *  @param[out] aux_state - Pointer to current operation state of FD/FDP
1633  *  @param[out] aux_state_status - Pointer to aux state status
1634  *  @param[out] progress_percent - Pointer to progress percentage
1635  *  @param[out] reason_code - Pointer to reason for entering current state
1636  *  @param[out] update_option_flags_enabled - Pointer to update option flags
1637  *                                            enabled
1638  *
1639  *  @return pldm_completion_codes
1640  */
1641 int decode_get_status_resp(const struct pldm_msg *msg, size_t payload_length,
1642 			   uint8_t *completion_code, uint8_t *current_state,
1643 			   uint8_t *previous_state, uint8_t *aux_state,
1644 			   uint8_t *aux_state_status, uint8_t *progress_percent,
1645 			   uint8_t *reason_code,
1646 			   bitfield32_t *update_option_flags_enabled);
1647 
1648 /** @brief Create PLDM request message for CancelUpdateComponent
1649  *
1650  *  @param[in] instance_id - Message's instance id
1651  *  @param[in,out] msg - Message will be written to this
1652  *  @param[in] payload_length - Length of request message payload
1653  *
1654  *  @return pldm_completion_codes
1655  *
1656  *  @note  Caller is responsible for memory alloc and dealloc of param
1657  *         'msg.payload'
1658  */
1659 int encode_cancel_update_component_req(uint8_t instance_id,
1660 				       struct pldm_msg *msg,
1661 				       size_t payload_length);
1662 
1663 /** @brief Decode CancelUpdateComponent response message
1664  *
1665  *  @param[in] msg - Response message
1666  *  @param[in] payload_length - Length of response message payload
1667  *  @param[out] completion_code - Pointer to the completion code
1668  *
1669  *  @return pldm_completion_codes
1670  */
1671 int decode_cancel_update_component_resp(const struct pldm_msg *msg,
1672 					size_t payload_length,
1673 					uint8_t *completion_code);
1674 
1675 /** @brief Create PLDM request message for CancelUpdate
1676  *
1677  *	@param[in] instance_id - Message's instance id
1678  *	@param[in,out] msg - Message will be written to this
1679  *  @param[in] payload_length - Length of request message payload
1680  *
1681  *	@return pldm_completion_codes
1682  *
1683  *	@note  Caller is responsible for memory alloc and dealloc of param
1684  *         'msg.payload'
1685  */
1686 int encode_cancel_update_req(uint8_t instance_id, struct pldm_msg *msg,
1687 			     size_t payload_length);
1688 
1689 /** @brief Decode CancelUpdate response message
1690  *
1691  *	@param[in] msg - Response message
1692  *  @param[in] payload_length - Length of response message payload
1693  *	@param[out] completion_code - Pointer to completion code
1694  *	@param[out] non_functioning_component_indication - Pointer to non
1695 						       functioning
1696  *                                                     component indication
1697  *	@param[out] non_functioning_component_bitmap - Pointer to non
1698  functioning
1699  *                                                 component bitmap
1700  *
1701  *	@return pldm_completion_codes
1702  */
1703 int decode_cancel_update_resp(const struct pldm_msg *msg, size_t payload_length,
1704 			      uint8_t *completion_code,
1705 			      bool8_t *non_functioning_component_indication,
1706 			      bitfield64_t *non_functioning_component_bitmap);
1707 
1708 #ifdef __cplusplus
1709 }
1710 #endif
1711 
1712 #endif // End of FW_UPDATE_H
1713