blob: f84b8c762c6d9e1e28534ee31a6c27aa8c2f836f [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 Joseph64af3452021-06-08 04:05:28 -070095/** @struct pldm_firmware_device_id_record
96 *
97 * Structure representing firmware device ID record
98 */
99struct pldm_firmware_device_id_record {
100 uint16_t record_length;
101 uint8_t descriptor_count;
102 bitfield32_t device_update_option_flags;
103 uint8_t comp_image_set_version_string_type;
104 uint8_t comp_image_set_version_string_length;
105 uint16_t fw_device_pkg_data_length;
106} __attribute__((packed));
107
Tom Joseph763b51e2021-06-05 04:50:47 -0700108/** @struct pldm_descriptor_tlv
109 *
110 * Structure representing descriptor type, length and value
111 */
112struct pldm_descriptor_tlv {
113 uint16_t descriptor_type;
114 uint16_t descriptor_length;
115 uint8_t descriptor_data[1];
116} __attribute__((packed));
117
118/** @struct pldm_vendor_defined_descriptor_title_data
119 *
120 * Structure representing vendor defined descriptor title sections
121 */
122struct pldm_vendor_defined_descriptor_title_data {
123 uint8_t vendor_defined_descriptor_title_str_type;
124 uint8_t vendor_defined_descriptor_title_str_len;
125 uint8_t vendor_defined_descriptor_title_str[1];
126} __attribute__((packed));
127
gokulsankereca3e192021-04-05 14:57:41 +0530128/** @struct pldm_query_device_identifiers_resp
129 *
130 * Structure representing query device identifiers response.
131 */
132struct pldm_query_device_identifiers_resp {
133 uint8_t completion_code;
134 uint32_t device_identifiers_len;
135 uint8_t descriptor_count;
136} __attribute__((packed));
137
gokulsanker22fbb342021-04-05 15:55:06 +0530138/** @struct pldm_get_firmware_parameters_resp
139 *
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700140 * Structure representing the fixed part of GetFirmwareParameters response
gokulsanker22fbb342021-04-05 15:55:06 +0530141 */
142struct pldm_get_firmware_parameters_resp {
143 uint8_t completion_code;
144 bitfield32_t capabilities_during_update;
145 uint16_t comp_count;
146 uint8_t active_comp_image_set_ver_str_type;
147 uint8_t active_comp_image_set_ver_str_len;
148 uint8_t pending_comp_image_set_ver_str_type;
149 uint8_t pending_comp_image_set_ver_str_len;
150} __attribute__((packed));
151
gokulsankere1fb7a82021-04-05 16:09:29 +0530152/** @struct pldm_component_parameter_entry
153 *
154 * Structure representing component parameter table entry.
155 */
156struct pldm_component_parameter_entry {
157 uint16_t comp_classification;
158 uint16_t comp_identifier;
159 uint8_t comp_classification_index;
160 uint32_t active_comp_comparison_stamp;
161 uint8_t active_comp_ver_str_type;
162 uint8_t active_comp_ver_str_len;
163 uint8_t active_comp_release_date[8];
164 uint32_t pending_comp_comparison_stamp;
165 uint8_t pending_comp_ver_str_type;
166 uint8_t pending_comp_ver_str_len;
167 uint8_t pending_comp_release_date[8];
168 bitfield16_t comp_activation_methods;
169 bitfield32_t capabilities_during_update;
170} __attribute__((packed));
171
Tom Joseph568e4702021-06-07 22:15:49 -0700172/** @brief Decode the PLDM package header information
173 *
174 * @param[in] data - pointer to package header information
175 * @param[in] length - available length in the firmware update package
176 * @param[out] package_header_info - pointer to fixed part of PLDM package
177 * header information
178 * @param[out] package_version_str - pointer to package version string
179 *
180 * @return pldm_completion_codes
181 */
182int decode_pldm_package_header_info(
183 const uint8_t *data, size_t length,
184 struct pldm_package_header_information *package_header_info,
185 struct variable_field *package_version_str);
186
Tom Joseph64af3452021-06-08 04:05:28 -0700187/** @brief Decode individual firmware device ID record
188 *
189 * @param[in] data - pointer to firmware device ID record
190 * @param[in] length - available length in the firmware update package
191 * @param[in] component_bitmap_bit_length - ComponentBitmapBitLengthfield
192 * parsed from the package header info
193 * @param[out] fw_device_id_record - pointer to fixed part of firmware device
194 * id record
195 * @param[out] applicable_components - pointer to ApplicableComponents
196 * @param[out] comp_image_set_version_str - pointer to
197 * ComponentImageSetVersionString
198 * @param[out] record_descriptors - pointer to RecordDescriptors
199 * @param[out] fw_device_pkg_data - pointer to FirmwareDevicePackageData
200 *
201 * @return pldm_completion_codes
202 */
203int decode_firmware_device_id_record(
204 const uint8_t *data, size_t length, uint16_t component_bitmap_bit_length,
205 struct pldm_firmware_device_id_record *fw_device_id_record,
206 struct variable_field *applicable_components,
207 struct variable_field *comp_image_set_version_str,
208 struct variable_field *record_descriptors,
209 struct variable_field *fw_device_pkg_data);
210
Tom Joseph763b51e2021-06-05 04:50:47 -0700211/** @brief Decode the record descriptor entries in the firmware update package
212 * and the Descriptors in the QueryDeviceIDentifiers command
213 *
214 * @param[in] data - pointer to descriptor entry
215 * @param[in] length - remaining length of the descriptor data
216 * @param[out] descriptor_type - pointer to descriptor type
217 * @param[out] descriptor_data - pointer to descriptor data
218 *
219 * @return pldm_completion_codes
220 */
221int decode_descriptor_type_length_value(const uint8_t *data, size_t length,
222 uint16_t *descriptor_type,
223 struct variable_field *descriptor_data);
224
225/** @brief Decode the vendor defined descriptor value
226 *
227 * @param[in] data - pointer to vendor defined descriptor value
228 * @param[in] length - length of the vendor defined descriptor value
229 * @param[out] descriptor_title_str_type - pointer to vendor defined descriptor
230 * title string type
231 * @param[out] descriptor_title_str - pointer to vendor defined descriptor
232 * title string
233 * @param[out] descriptor_data - pointer to vendor defined descriptor data
234 *
235 * @return pldm_completion_codes
236 */
237int decode_vendor_defined_descriptor_value(
238 const uint8_t *data, size_t length, uint8_t *descriptor_title_str_type,
239 struct variable_field *descriptor_title_str,
240 struct variable_field *descriptor_data);
241
gokulsanker138ceba2021-04-05 13:25:25 +0530242/** @brief Create a PLDM request message for QueryDeviceIdentifiers
243 *
244 * @param[in] instance_id - Message's instance id
245 * @param[in] payload_length - Length of the request message payload
246 * @param[in,out] msg - Message will be written to this
247 *
248 * @return pldm_completion_codes
249 *
250 * @note Caller is responsible for memory alloc and dealloc of param
251 * 'msg.payload'
252 */
253int encode_query_device_identifiers_req(uint8_t instance_id,
254 size_t payload_length,
255 struct pldm_msg *msg);
gokulsankereca3e192021-04-05 14:57:41 +0530256
257/** @brief Decode QueryDeviceIdentifiers response message
258 *
259 * @param[in] msg - Response message
260 * @param[in] payload_length - Length of response message payload
261 * @param[out] completion_code - Pointer to response msg's PLDM completion code
262 * @param[out] device_identifiers_len - Pointer to device identifiers length
263 * @param[out] descriptor_count - Pointer to descriptor count
264 * @param[out] descriptor_data - Pointer to descriptor data
265 *
266 * @return pldm_completion_codes
267 */
268int decode_query_device_identifiers_resp(const struct pldm_msg *msg,
269 size_t payload_length,
270 uint8_t *completion_code,
271 uint32_t *device_identifiers_len,
272 uint8_t *descriptor_count,
273 uint8_t **descriptor_data);
gokulsanker981fbfb2021-04-05 15:17:25 +0530274
275/** @brief Create a PLDM request message for GetFirmwareParameters
276 *
277 * @param[in] instance_id - Message's instance id
278 * @param[in] payload_length - Length of the request message payload
279 * @param[in,out] msg - Message will be written to this
280 *
281 * @return pldm_completion_codes
282 *
283 * @note Caller is responsible for memory alloc and dealloc of param
284 * 'msg.payload'
285 */
286int encode_get_firmware_parameters_req(uint8_t instance_id,
287 size_t payload_length,
288 struct pldm_msg *msg);
gokulsanker22fbb342021-04-05 15:55:06 +0530289
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700290/** @brief Decode GetFirmwareParameters response
gokulsanker22fbb342021-04-05 15:55:06 +0530291 *
292 * @param[in] msg - Response message
293 * @param[in] payload_length - Length of response message payload
294 * @param[out] resp_data - Pointer to get firmware parameters response
295 * @param[out] active_comp_image_set_ver_str - Pointer to active component
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700296 * image set version string
gokulsanker22fbb342021-04-05 15:55:06 +0530297 * @param[out] pending_comp_image_set_ver_str - Pointer to pending component
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700298 * image set version string
299 * @param[out] comp_parameter_table - Pointer to component parameter table
gokulsanker22fbb342021-04-05 15:55:06 +0530300 *
301 * @return pldm_completion_codes
302 */
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700303int decode_get_firmware_parameters_resp(
gokulsanker22fbb342021-04-05 15:55:06 +0530304 const struct pldm_msg *msg, size_t payload_length,
305 struct pldm_get_firmware_parameters_resp *resp_data,
306 struct variable_field *active_comp_image_set_ver_str,
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700307 struct variable_field *pending_comp_image_set_ver_str,
308 struct variable_field *comp_parameter_table);
gokulsanker22fbb342021-04-05 15:55:06 +0530309
gokulsankere1fb7a82021-04-05 16:09:29 +0530310/** @brief Decode component entries in the component parameter table which is
311 * part of the response of GetFirmwareParameters command
312 *
313 * @param[in] data - Component entry
314 * @param[in] length - Length of component entry
315 * @param[out] component_data - Pointer to component parameter table
316 * @param[out] active_comp_ver_str - Pointer to active component version string
317 * @param[out] pending_comp_ver_str - Pointer to pending component version
318 * string
319 *
320 * @return pldm_completion_codes
321 */
322int decode_get_firmware_parameters_resp_comp_entry(
323 const uint8_t *data, size_t length,
324 struct pldm_component_parameter_entry *component_data,
325 struct variable_field *active_comp_ver_str,
326 struct variable_field *pending_comp_ver_str);
327
gokulsanker138ceba2021-04-05 13:25:25 +0530328#ifdef __cplusplus
329}
330#endif
331
332#endif // End of FW_UPDATE_H