blob: 44a2850411e72d962597b65ea44cec40fbae367e [file] [log] [blame]
gokulsanker138ceba2021-04-05 13:25:25 +05301#ifndef FW_UPDATE_H
2#define FW_UPDATE_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7#include "base.h"
gokulsanker22fbb342021-04-05 15:55:06 +05308#include "utils.h"
gokulsanker138ceba2021-04-05 13:25:25 +05309
10#define PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES 0
gokulsankereca3e192021-04-05 14:57:41 +053011/** @brief Minimum length of device descriptor, 2 bytes for descriptor type,
12 * 2 bytes for descriptor length and atleast 1 byte of descriptor data
13 */
14#define PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN 5
gokulsanker981fbfb2021-04-05 15:17:25 +053015#define PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES 0
gokulsanker138ceba2021-04-05 13:25:25 +053016
17/** @brief PLDM Firmware update commands
18 */
gokulsanker981fbfb2021-04-05 15:17:25 +053019enum pldm_firmware_update_commands {
20 PLDM_QUERY_DEVICE_IDENTIFIERS = 0x01,
21 PLDM_GET_FIRMWARE_PARAMETERS = 0x02
22};
gokulsanker138ceba2021-04-05 13:25:25 +053023
Tom Joseph763b51e2021-06-05 04:50:47 -070024/** @brief String type values defined in the PLDM firmware update specification
25 */
26enum pldm_firmware_update_string_type {
27 PLDM_STR_TYPE_UNKNOWN = 0,
28 PLDM_STR_TYPE_ASCII = 1,
29 PLDM_STR_TYPE_UTF_8 = 2,
30 PLDM_STR_TYPE_UTF_16 = 3,
31 PLDM_STR_TYPE_UTF_16LE = 4,
32 PLDM_STR_TYPE_UTF_16BE = 5
33};
34
35/** @brief Descriptor types defined in PLDM firmware update specification
36 */
37enum pldm_firmware_update_descriptor_types {
38 PLDM_FWUP_PCI_VENDOR_ID = 0x0000,
39 PLDM_FWUP_IANA_ENTERPRISE_ID = 0x0001,
40 PLDM_FWUP_UUID = 0x0002,
41 PLDM_FWUP_PNP_VENDOR_ID = 0x0003,
42 PLDM_FWUP_ACPI_VENDOR_ID = 0x0004,
43 PLDM_FWUP_IEEE_ASSIGNED_COMPANY_ID = 0x0005,
44 PLDM_FWUP_SCSI_VENDOR_ID = 0x0006,
45 PLDM_FWUP_PCI_DEVICE_ID = 0x0100,
46 PLDM_FWUP_PCI_SUBSYSTEM_VENDOR_ID = 0x0101,
47 PLDM_FWUP_PCI_SUBSYSTEM_ID = 0x0102,
48 PLDM_FWUP_PCI_REVISION_ID = 0x0103,
49 PLDM_FWUP_PNP_PRODUCT_IDENTIFIER = 0x0104,
50 PLDM_FWUP_ACPI_PRODUCT_IDENTIFIER = 0x0105,
51 PLDM_FWUP_ASCII_MODEL_NUMBER_LONG_STRING = 0x0106,
52 PLDM_FWUP_ASCII_MODEL_NUMBER_SHORT_STRING = 0x0107,
53 PLDM_FWUP_SCSI_PRODUCT_ID = 0x0108,
54 PLDM_FWUP_UBM_CONTROLLER_DEVICE_CODE = 0x0109,
55 PLDM_FWUP_VENDOR_DEFINED = 0xFFFF
56};
57
58/** @brief Descriptor types length defined in PLDM firmware update specification
59 */
60enum pldm_firmware_update_descriptor_types_length {
61 PLDM_FWUP_PCI_VENDOR_ID_LENGTH = 2,
62 PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH = 4,
63 PLDM_FWUP_UUID_LENGTH = 16,
64 PLDM_FWUP_PNP_VENDOR_ID_LENGTH = 3,
65 PLDM_FWUP_ACPI_VENDOR_ID_LENGTH = 4,
66 PLDM_FWUP_IEEE_ASSIGNED_COMPANY_ID_LENGTH = 3,
67 PLDM_FWUP_SCSI_VENDOR_ID_LENGTH = 8,
68 PLDM_FWUP_PCI_DEVICE_ID_LENGTH = 2,
69 PLDM_FWUP_PCI_SUBSYSTEM_VENDOR_ID_LENGTH = 2,
70 PLDM_FWUP_PCI_SUBSYSTEM_ID_LENGTH = 2,
71 PLDM_FWUP_PCI_REVISION_ID_LENGTH = 1,
72 PLDM_FWUP_PNP_PRODUCT_IDENTIFIER_LENGTH = 4,
73 PLDM_FWUP_ACPI_PRODUCT_IDENTIFIER_LENGTH = 4,
74 PLDM_FWUP_ASCII_MODEL_NUMBER_LONG_STRING_LENGTH = 40,
75 PLDM_FWUP_ASCII_MODEL_NUMBER_SHORT_STRING_LENGTH = 10,
76 PLDM_FWUP_SCSI_PRODUCT_ID_LENGTH = 16,
77 PLDM_FWUP_UBM_CONTROLLER_DEVICE_CODE_LENGTH = 4
78};
79
80/** @struct pldm_descriptor_tlv
81 *
82 * Structure representing descriptor type, length and value
83 */
84struct pldm_descriptor_tlv {
85 uint16_t descriptor_type;
86 uint16_t descriptor_length;
87 uint8_t descriptor_data[1];
88} __attribute__((packed));
89
90/** @struct pldm_vendor_defined_descriptor_title_data
91 *
92 * Structure representing vendor defined descriptor title sections
93 */
94struct pldm_vendor_defined_descriptor_title_data {
95 uint8_t vendor_defined_descriptor_title_str_type;
96 uint8_t vendor_defined_descriptor_title_str_len;
97 uint8_t vendor_defined_descriptor_title_str[1];
98} __attribute__((packed));
99
gokulsankereca3e192021-04-05 14:57:41 +0530100/** @struct pldm_query_device_identifiers_resp
101 *
102 * Structure representing query device identifiers response.
103 */
104struct pldm_query_device_identifiers_resp {
105 uint8_t completion_code;
106 uint32_t device_identifiers_len;
107 uint8_t descriptor_count;
108} __attribute__((packed));
109
gokulsanker22fbb342021-04-05 15:55:06 +0530110/** @struct pldm_get_firmware_parameters_resp
111 *
112 * Structure representing get firmware parameters response.
113 */
114struct pldm_get_firmware_parameters_resp {
115 uint8_t completion_code;
116 bitfield32_t capabilities_during_update;
117 uint16_t comp_count;
118 uint8_t active_comp_image_set_ver_str_type;
119 uint8_t active_comp_image_set_ver_str_len;
120 uint8_t pending_comp_image_set_ver_str_type;
121 uint8_t pending_comp_image_set_ver_str_len;
122} __attribute__((packed));
123
gokulsankere1fb7a82021-04-05 16:09:29 +0530124/** @struct pldm_component_parameter_entry
125 *
126 * Structure representing component parameter table entry.
127 */
128struct pldm_component_parameter_entry {
129 uint16_t comp_classification;
130 uint16_t comp_identifier;
131 uint8_t comp_classification_index;
132 uint32_t active_comp_comparison_stamp;
133 uint8_t active_comp_ver_str_type;
134 uint8_t active_comp_ver_str_len;
135 uint8_t active_comp_release_date[8];
136 uint32_t pending_comp_comparison_stamp;
137 uint8_t pending_comp_ver_str_type;
138 uint8_t pending_comp_ver_str_len;
139 uint8_t pending_comp_release_date[8];
140 bitfield16_t comp_activation_methods;
141 bitfield32_t capabilities_during_update;
142} __attribute__((packed));
143
Tom Joseph763b51e2021-06-05 04:50:47 -0700144/** @brief Decode the record descriptor entries in the firmware update package
145 * and the Descriptors in the QueryDeviceIDentifiers command
146 *
147 * @param[in] data - pointer to descriptor entry
148 * @param[in] length - remaining length of the descriptor data
149 * @param[out] descriptor_type - pointer to descriptor type
150 * @param[out] descriptor_data - pointer to descriptor data
151 *
152 * @return pldm_completion_codes
153 */
154int decode_descriptor_type_length_value(const uint8_t *data, size_t length,
155 uint16_t *descriptor_type,
156 struct variable_field *descriptor_data);
157
158/** @brief Decode the vendor defined descriptor value
159 *
160 * @param[in] data - pointer to vendor defined descriptor value
161 * @param[in] length - length of the vendor defined descriptor value
162 * @param[out] descriptor_title_str_type - pointer to vendor defined descriptor
163 * title string type
164 * @param[out] descriptor_title_str - pointer to vendor defined descriptor
165 * title string
166 * @param[out] descriptor_data - pointer to vendor defined descriptor data
167 *
168 * @return pldm_completion_codes
169 */
170int decode_vendor_defined_descriptor_value(
171 const uint8_t *data, size_t length, uint8_t *descriptor_title_str_type,
172 struct variable_field *descriptor_title_str,
173 struct variable_field *descriptor_data);
174
gokulsanker138ceba2021-04-05 13:25:25 +0530175/** @brief Create a PLDM request message for QueryDeviceIdentifiers
176 *
177 * @param[in] instance_id - Message's instance id
178 * @param[in] payload_length - Length of the request message payload
179 * @param[in,out] msg - Message will be written to this
180 *
181 * @return pldm_completion_codes
182 *
183 * @note Caller is responsible for memory alloc and dealloc of param
184 * 'msg.payload'
185 */
186int encode_query_device_identifiers_req(uint8_t instance_id,
187 size_t payload_length,
188 struct pldm_msg *msg);
gokulsankereca3e192021-04-05 14:57:41 +0530189
190/** @brief Decode QueryDeviceIdentifiers response message
191 *
192 * @param[in] msg - Response message
193 * @param[in] payload_length - Length of response message payload
194 * @param[out] completion_code - Pointer to response msg's PLDM completion code
195 * @param[out] device_identifiers_len - Pointer to device identifiers length
196 * @param[out] descriptor_count - Pointer to descriptor count
197 * @param[out] descriptor_data - Pointer to descriptor data
198 *
199 * @return pldm_completion_codes
200 */
201int decode_query_device_identifiers_resp(const struct pldm_msg *msg,
202 size_t payload_length,
203 uint8_t *completion_code,
204 uint32_t *device_identifiers_len,
205 uint8_t *descriptor_count,
206 uint8_t **descriptor_data);
gokulsanker981fbfb2021-04-05 15:17:25 +0530207
208/** @brief Create a PLDM request message for GetFirmwareParameters
209 *
210 * @param[in] instance_id - Message's instance id
211 * @param[in] payload_length - Length of the request message payload
212 * @param[in,out] msg - Message will be written to this
213 *
214 * @return pldm_completion_codes
215 *
216 * @note Caller is responsible for memory alloc and dealloc of param
217 * 'msg.payload'
218 */
219int encode_get_firmware_parameters_req(uint8_t instance_id,
220 size_t payload_length,
221 struct pldm_msg *msg);
gokulsanker22fbb342021-04-05 15:55:06 +0530222
223/** @brief Decode GetFirmwareParameters response parameters except the
224 * ComponentParameterTable
225 *
226 * @param[in] msg - Response message
227 * @param[in] payload_length - Length of response message payload
228 * @param[out] resp_data - Pointer to get firmware parameters response
229 * @param[out] active_comp_image_set_ver_str - Pointer to active component
230 * image set version string
231 * @param[out] pending_comp_image_set_ver_str - Pointer to pending component
232 * image set version string
233 *
234 * @return pldm_completion_codes
235 */
236int decode_get_firmware_parameters_resp_comp_set_info(
237 const struct pldm_msg *msg, size_t payload_length,
238 struct pldm_get_firmware_parameters_resp *resp_data,
239 struct variable_field *active_comp_image_set_ver_str,
240 struct variable_field *pending_comp_image_set_ver_str);
241
gokulsankere1fb7a82021-04-05 16:09:29 +0530242/** @brief Decode component entries in the component parameter table which is
243 * part of the response of GetFirmwareParameters command
244 *
245 * @param[in] data - Component entry
246 * @param[in] length - Length of component entry
247 * @param[out] component_data - Pointer to component parameter table
248 * @param[out] active_comp_ver_str - Pointer to active component version string
249 * @param[out] pending_comp_ver_str - Pointer to pending component version
250 * string
251 *
252 * @return pldm_completion_codes
253 */
254int decode_get_firmware_parameters_resp_comp_entry(
255 const uint8_t *data, size_t length,
256 struct pldm_component_parameter_entry *component_data,
257 struct variable_field *active_comp_ver_str,
258 struct variable_field *pending_comp_ver_str);
259
gokulsanker138ceba2021-04-05 13:25:25 +0530260#ifdef __cplusplus
261}
262#endif
263
264#endif // End of FW_UPDATE_H