blob: 456c051922b58ff24c8e06d493ff111a86444b40 [file] [log] [blame]
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +05301#ifndef FRU_H
2#define FRU_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <asm/byteorder.h>
9#include <stddef.h>
10#include <stdint.h>
11
12#include "base.h"
John Wang9fa87cf2020-06-10 17:53:40 +080013#include "utils.h"
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053014
Christian Geddes3bdb3c22020-05-01 14:55:39 -050015#define PLDM_GET_FRU_RECORD_TABLE_METADATA_REQ_BYTES 0
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053016#define PLDM_GET_FRU_RECORD_TABLE_METADATA_RESP_BYTES 19
PriyangaRamasamy497665a2019-07-30 12:48:25 +053017#define PLDM_GET_FRU_RECORD_TABLE_REQ_BYTES 5
18#define PLDM_GET_FRU_RECORD_TABLE_MIN_RESP_BYTES 6
John Wang9fa87cf2020-06-10 17:53:40 +080019#define PLDM_GET_FRU_RECORD_BY_OPTION_MIN_RESP_BYTES 6
Sridevi Ramesh9cb05bd2021-05-31 08:37:33 -050020#define PLDM_SET_FRU_RECORD_TABLE_MIN_REQ_BYTES 5
21#define PLDM_SET_FRU_RECORD_TABLE_RESP_BYTES 5
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053022
Christian Geddes3bdb3c22020-05-01 14:55:39 -050023#define FRU_TABLE_CHECKSUM_SIZE 4
24
John Wang9e82ad12020-06-12 10:53:32 +080025enum pldm_fru_completion_codes {
Sridevi Ramesh9cb05bd2021-05-31 08:37:33 -050026 PLDM_FRU_INVALID_DATA_TRANSFER_HANDLE = 0x80,
27 PLDM_FRU_INVALID_TRANSFER_FLAG = 0x82,
28 PLDM_FRU_DATA_INVALID_DATA_INTEGRITY_CHECK = 0x84,
John Wang9e82ad12020-06-12 10:53:32 +080029 PLDM_FRU_DATA_STRUCTURE_TABLE_UNAVAILABLE = 0x85,
30};
31
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053032/** @brief PLDM FRU commands
33 */
34enum pldm_fru_commands {
35 PLDM_GET_FRU_RECORD_TABLE_METADATA = 0X01,
PriyangaRamasamy497665a2019-07-30 12:48:25 +053036 PLDM_GET_FRU_RECORD_TABLE = 0X02,
PriyangaRamasamyf3295be2019-07-23 12:18:40 +053037 PLDM_SET_FRU_RECORD_TABLE = 0X03,
38 PLDM_GET_FRU_RECORD_BY_OPTION = 0X04
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053039};
40
Tom Joseph93d68712020-01-07 10:24:41 +053041/** @brief FRU record types
42 */
43enum pldm_fru_record_type {
44 PLDM_FRU_RECORD_TYPE_GENERAL = 0X01,
45 PLDM_FRU_RECORD_TYPE_OEM = 0XFE,
46};
47
48/** @brief Encoding type for FRU fields
49 */
50enum pldm_fru_field_encoding {
51 PLDM_FRU_ENCODING_UNSPECIFIED = 0X00,
52 PLDM_FRU_ENCODING_ASCII = 0X01,
53 PLDM_FRU_ENCODING_UTF8 = 0X02,
54 PLDM_FRU_ENCODING_UTF16 = 0X03,
55 PLDM_FRU_ENCODING_UTF16LE = 0X04,
56 PLDM_FRU_ENCODING_UTF16BE = 0X05,
57};
58
59/** @brief FRU field types
60 */
61enum pldm_fru_field_type {
62 PLDM_FRU_FIELD_TYPE_CHASSIS = 0X01,
63 PLDM_FRU_FIELD_TYPE_MODEL = 0X02,
64 PLDM_FRU_FIELD_TYPE_PN = 0X03,
65 PLDM_FRU_FIELD_TYPE_SN = 0X04,
66 PLDM_FRU_FIELD_TYPE_MANUFAC = 0X05,
67 PLDM_FRU_FIELD_TYPE_MANUFAC_DATE = 0X06,
68 PLDM_FRU_FIELD_TYPE_VENDOR = 0X07,
69 PLDM_FRU_FIELD_TYPE_NAME = 0X08,
70 PLDM_FRU_FIELD_TYPE_SKU = 0X09,
71 PLDM_FRU_FIELD_TYPE_VERSION = 0X0A,
72 PLDM_FRU_FIELD_TYPE_ASSET_TAG = 0X0B,
73 PLDM_FRU_FIELD_TYPE_DESC = 0X0C,
74 PLDM_FRU_FIELD_TYPE_EC_LVL = 0X0D,
75 PLDM_FRU_FIELD_TYPE_OTHER = 0X0E,
76 PLDM_FRU_FIELD_TYPE_IANA = 0X0F,
77};
78
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053079/** @struct pldm_get_fru_record_table_metadata_resp
80 *
81 * Structure representing PLDM get FRU table metadata response.
82 */
83struct pldm_get_fru_record_table_metadata_resp {
84 uint8_t completion_code; //!< completion code
85 uint8_t fru_data_major_version; //!< The major version of the FRU Record
86 uint8_t fru_data_minor_version; //!< The minor version of the FRU Record
87 uint32_t
88 fru_table_maximum_size; //!< The size of the largest FRU Record data
89 uint32_t fru_table_length; //!< The total length of the FRU Record Table
90 uint16_t total_record_set_identifiers; //!< The total number of FRU
91 //!< Record Data structures
92 uint16_t
93 total_table_records; //!< The total number of records in the table
94 uint32_t
95 checksum; //!< The integrity checksum on the FRU Record Table data
96} __attribute__((packed));
97
PriyangaRamasamy497665a2019-07-30 12:48:25 +053098/** @struct pldm_get_fru_record_table_req
99 *
100 * Structure representing PLDM get FRU record table request.
101 */
102struct pldm_get_fru_record_table_req {
103 uint32_t data_transfer_handle;
104 uint8_t transfer_operation_flag;
105} __attribute__((packed));
106
107/** @struct pldm_get_fru_record_table_resp
108 *
109 * Structure representing PLDM get FRU record table response.
110 */
111struct pldm_get_fru_record_table_resp {
112 uint8_t completion_code;
113 uint32_t next_data_transfer_handle;
114 uint8_t transfer_flag;
115 uint8_t fru_record_table_data[1];
116} __attribute__((packed));
117
John Wang9fa87cf2020-06-10 17:53:40 +0800118struct pldm_get_fru_record_by_option_req {
119 uint32_t data_transfer_handle;
120 uint16_t fru_table_handle;
121 uint16_t record_set_identifier;
122 uint8_t record_type;
123 uint8_t field_type;
124 uint8_t transfer_op_flag;
125} __attribute__((packed));
126
127struct pldm_get_fru_record_by_option_resp {
128 uint8_t completion_code;
129 uint32_t next_data_transfer_handle;
130 uint8_t transfer_flag;
131 uint8_t fru_structure_data[1];
132} __attribute__((packed));
133
Sridevi Ramesh9cb05bd2021-05-31 08:37:33 -0500134struct pldm_set_fru_record_table_req {
135 uint32_t data_transfer_handle;
136 uint8_t transfer_flag;
137 uint8_t fru_record_table_data[1];
138} __attribute__((packed));
139
140struct pldm_set_fru_record_table_resp {
141 uint8_t completion_code;
142 uint32_t next_data_transfer_handle;
143} __attribute__((packed));
144
Tom Joseph93d68712020-01-07 10:24:41 +0530145/** @struct pldm_fru_record_tlv
146 *
147 * Structure representing each FRU field entry (type, length, value)
148 */
149struct pldm_fru_record_tlv {
150 uint8_t type;
151 uint8_t length;
152 uint8_t value[1];
153} __attribute__((packed));
154
155/** @struct pldm_fru_record_data_format
156 *
157 * Structure representing the FRU record data format
158 */
159struct pldm_fru_record_data_format {
160 uint16_t record_set_id;
161 uint8_t record_type;
162 uint8_t num_fru_fields;
163 uint8_t encoding_type;
164 struct pldm_fru_record_tlv tlvs[1];
165} __attribute__((packed));
166
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530167/* Requester */
168
169/* GetFRURecordTableMetadata */
170
171/** @brief Create a PLDM request message for GetFRURecordTableMetadata
172 *
173 * @param[in] instance_id - Message's instance id
174 * @param[in,out] msg - Message will be written to this
Christian Geddes3bdb3c22020-05-01 14:55:39 -0500175 * @param[in] payload_length - Length of the request message payload
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530176 * @return pldm_completion_codes
177 * @note Caller is responsible for memory alloc and dealloc of param
178 * 'msg.payload'
179 */
180int encode_get_fru_record_table_metadata_req(uint8_t instance_id,
Christian Geddes3bdb3c22020-05-01 14:55:39 -0500181 struct pldm_msg *msg,
182 size_t payload_length);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530183
184/** @brief Decode GetFruRecordTable response data
185 *
George Liu684a7162019-12-06 15:10:52 +0800186 * Note:
187 * * If the return value is not PLDM_SUCCESS, it represents a
188 * transport layer error.
189 * * If the completion_code value is not PLDM_SUCCESS, it represents a
190 * protocol layer error and all the out-parameters are invalid.
191 *
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530192 * @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] fru_data_major_version - Major version of the FRU Record
196 * @param[out] fru_data_minor_version - Minor version of the FRU Record
197 * @param[out] fru_table_maximum_size - Size of the largest FRU Record data
198 * @param[out] fru_table_length - Total length of the FRU Record Table
199 * @param[out] total_Record_Set_Identifiers - Total number of FRU Record Data
200 * structures
201 * @param[out] total_table_records - Total number of records in the table
202 * @param[out] checksum - integrity checksum on the FRU Record Table data
203 * @return pldm_completion_codes
204 */
205int decode_get_fru_record_table_metadata_resp(
206 const struct pldm_msg *msg, size_t payload_length, uint8_t *completion_code,
207 uint8_t *fru_data_major_version, uint8_t *fru_data_minor_version,
208 uint32_t *fru_table_maximum_size, uint32_t *fru_table_length,
209 uint16_t *total_record_set_identifiers, uint16_t *total_table_records,
210 uint32_t *checksum);
211
212/* Responder */
213
214/* GetFRURecordTableMetadata */
215
216/** @brief Create a PLDM response message for GetFRURecordTableMetadata
217 *
218 * @param[in] instance_id - Message's instance id
219 * @param[in] completion_code - PLDM completion code
220 * @param[in] fru_data_major_version - Major version of the FRU Record
221 * @param[in] fru_data_minor_version - Minor version of the FRU Record
222 * @param[in] fru_table_maximum_size - Size of the largest FRU Record data
223 * @param[in] fru_table_length - Total length of the FRU Record Table
224 * @param[in] total_Record_Set_Identifiers - Total number of FRU Record Data
225 * structures
226 * @param[in] total_table_records - Total number of records in the table
227 * @param[in] checksum - integrity checksum on the FRU Record Table data
228 * @param[in,out] msg - Message will be written to this
229 * @return pldm_completion_codes
230 * @note Caller is responsible for memory alloc and dealloc of param
231 * 'msg.payload'
232 */
233
234int encode_get_fru_record_table_metadata_resp(
235 uint8_t instance_id, uint8_t completion_code,
236 uint8_t fru_data_major_version, uint8_t fru_data_minor_version,
237 uint32_t fru_table_maximum_size, uint32_t fru_table_length,
238 uint16_t total_record_set_identifiers, uint16_t total_table_records,
239 uint32_t checksum, struct pldm_msg *msg);
240
PriyangaRamasamy497665a2019-07-30 12:48:25 +0530241/* GetFruRecordTable */
242
243/** @brief Decode GetFruRecordTable request data
244 *
245 * @param[in] msg - PLDM request message payload
246 * @param[in] payload_length - Length of request payload
247 * @param[out] data_transfer_handle - A handle, used to identify a FRU Record
248 * Table data transfer
249 * @param[out] transfer_operation_flag - A flag that indicates whether this is
250 * the start of the transfer
251 * @return pldm_completion_codes
252 */
253int decode_get_fru_record_table_req(const struct pldm_msg *msg,
254 size_t payload_length,
255 uint32_t *data_transfer_handle,
256 uint8_t *transfer_operation_flag);
257
258/** @brief Create a PLDM response message for GetFruRecordTable
259 *
260 * @param[in] instance_id - Message's instance id
261 * @param[in] completion_code - PLDM completion code
262 * @param[in] next_data_transfer_handle - A handle that is used to identify the
263 * next portion of the transfer
264 * @param[in] transfer_flag - The transfer flag that indicates what part of the
265 * transfer this response represents
266 * @param[in,out] msg - Message will be written to this
267 * @return pldm_completion_codes
268 * @note Caller is responsible for memory alloc and dealloc of param 'msg',
269 * and for appending the FRU table to the msg.
270 */
271int encode_get_fru_record_table_resp(uint8_t instance_id,
272 uint8_t completion_code,
273 uint32_t next_data_transfer_handle,
274 uint8_t transfer_flag,
275 struct pldm_msg *msg);
John Wang9fa87cf2020-06-10 17:53:40 +0800276
277/* GetFRURecordByOption */
278
279/** @brief Decode GetFRURecordByOption request data
280 *
281 * @param[in] msg - PLDM request message payload
282 * @param[in] payload_length - Length of request payload
283 * @param[out] data_transfer_handle - A handle, used to identify a FRU Record
284 * Table data transfer
285 * @param[out] fru_table_handle - A handle, used to identify a FRU DATA
286 * records
287 * @param[out] record_set_identifier - FRU record set identifier
288 * @param[out] record_type - FRU record type
289 * @param[out] field_type - FRU field type
290 * @param[out] transfer_op_flag - A flag that indicates whether this is
291 * the start of the transfer
292 * @return pldm_completion_codes
293 */
294int decode_get_fru_record_by_option_req(
295 const struct pldm_msg *msg, size_t payload_length,
296 uint32_t *data_transfer_handle, uint16_t *fru_table_handle,
297 uint16_t *record_set_identifier, uint8_t *record_type, uint8_t *field_type,
298 uint8_t *transfer_op_flag);
299
300/** @brief Encode GetFRURecordByOption response data
301 *
302 * @param[in] instance_id - Message's instance id
303 * @param[in] completion_code - PLDM completion code
304 * @param[in] next_data_transfer_handle - A handle that is used to identify the
305 * next portion of the transfer
306 * @param[in] transfer_flag - The transfer flag that indicates what part of the
307 * transfer this response represents
308 * @param[in] fru_structure_data - FRU Structure Data
309 * @param[in] data_size - Size of FRU Structrue Data
310 * @param[in,out] msg - Message will be written to this
311 * @return pldm_completion_codes
312 * @note Caller is responsible for memory alloc and dealloc of param 'msg',
313 * and for appending the FRU table to the msg.
314 */
315int encode_get_fru_record_by_option_resp(uint8_t instance_id,
316 uint8_t completion_code,
317 uint32_t next_data_transfer_handle,
318 uint8_t transfer_flag,
319 const void *fru_structure_data,
320 size_t data_size, struct pldm_msg *msg,
321 size_t payload_length);
322
PriyangaRamasamyf3295be2019-07-23 12:18:40 +0530323/* Requester */
324
325/* GetFruRecordTable */
326
327/** @brief Create a PLDM request message for GetFruRecordTable
328 *
329 * @param[in] instance_id - Message's instance id
330 * @param[in] data_transfer_handle - A handle, used to identify a FRU Record
331 * Table data transfer
332 * @param[in] transfer_operation_flag - A flag that indicates whether this is
333 * the start of the transfer
334 * @param[in,out] msg - Message will be written to this
335 * @param[in] payload_length - Length of request message payload
336 * @return pldm_completion_codes
337 * @note Caller is responsible for memory alloc and dealloc of param
338 * 'msg.payload'
339 */
340
341int encode_get_fru_record_table_req(uint8_t instance_id,
342 uint32_t data_transfer_handle,
343 uint8_t transfer_operation_flag,
344 struct pldm_msg *msg,
345 size_t payload_length);
346
347/** @brief Decode GetFruRecordTable response data
348 *
349 * @param[in] msg - Response message
350 * @param[in] payload_length - Length of response message payload
351 * @param[out] completion_code - Pointer to response msg's PLDM completion code
352 * @param[out] next_data_transfer_handle - A handle used to identify the next
353 * portion of the transfer
354 * @param[out] transfer_flag - The transfer flag that indicates what part of
355 * the transfer this response represents
356 * @param[out] fru_record_table_data - This data is a portion of the overall
357 * FRU Record Table
358 * @param[out] fru_record_table_length - Length of the FRU record table data
359 * @return pldm_completion_codes
360 */
361
362int decode_get_fru_record_table_resp(
363 const struct pldm_msg *msg, size_t payload_length, uint8_t *completion_code,
364 uint32_t *next_data_transfer_handle, uint8_t *transfer_flag,
365 uint8_t *fru_record_table_data, size_t *fru_record_table_length);
PriyangaRamasamy497665a2019-07-30 12:48:25 +0530366
Tom Joseph93d68712020-01-07 10:24:41 +0530367/** @brief Encode the FRU record in the FRU table
368 *
369 * @param[in/out] fru_table - Pointer to the FRU table
370 * @param[in] total_size - The size of the table,including the size of FRU
371 * record to be added to the table.
372 * @param[in/out] curr_size - The size of the table, excluding the size of FRU
373 * record to be added to the table.
374 * @param[in] record_set_id - FRU record set identifier
375 * @param[in] record_type - FRU record type
376 * @param[in] num_frus - Number of FRU fields
377 * @param[in] encoding - Encoding type for FRU fields
378 * @param[in] tlvs - Pointer to the buffer with all the FRU fields
379 * @param[in] tlvs_size - Size of the buffer with all the FRU fields
380 *
381 * @return pldm_completion_codes
382 */
383int encode_fru_record(uint8_t *fru_table, size_t total_size, size_t *curr_size,
384 uint16_t record_set_id, uint8_t record_type,
385 uint8_t num_frus, uint8_t encoding, uint8_t *tlvs,
386 size_t tlvs_size);
387
John Wang9fa87cf2020-06-10 17:53:40 +0800388/* GetFRURecordByOption */
389
390/** @brief Create a PLDM request message for GetFRURecordByOption
391 *
392 * @param[in] instance_id - Message's instance id
393 * @param[in] data_transfer_handle - A handle, used to identify a FRU Record
394 * Table data transfer
395 * @param[in] fru_table_handle - A handle, used to identify a FRU DATA records
396 * @param[in] record_set_identifier - FRU record set identifier
397 * @param[in] record_type - FRU record type
398 * @param[in] field_type - FRU field type
399 * @param[in] transfer_op_flag - A flag that indicates whether this is
400 * the start of the transfer
401 * @param[in,out] msg - Message will be written to this
402 * @param[in] payload_length - Length of request message payload
403 * @return pldm_completion_codes
404 * @note Caller is responsible for memory alloc and dealloc of param
405 * 'msg.payload'
406 */
407int encode_get_fru_record_by_option_req(
408 uint8_t instance_id, uint32_t data_transfer_handle,
409 uint16_t fru_table_handle, uint16_t record_set_identifier,
410 uint8_t record_type, uint8_t field_type, uint8_t transfer_op_flag,
411 struct pldm_msg *msg, size_t payload_length);
412
413/** @brief Decode GetFRURecordByOption response data
414 *
415 * @param[in] msg - Response message
416 * @param[in] payload_length - Length of response message payload
417 * @param[out] completion_code - Pointer to response msg's PLDM completion code
418 * @param[out] next_data_transfer_handle - A handle used to identify the next
419 * portion of the transfer
420 * @param[out] transfer_flag - The transfer flag that indicates what part of
421 * the transfer this response represents
422 * @param[out] fru_structure_data - FRU Structure Data
423 * @return pldm_completion_codes
424 */
425int decode_get_fru_record_by_option_resp(
426 const struct pldm_msg *msg, size_t payload_length, uint8_t *completion_code,
427 uint32_t *next_transfer_handle, uint8_t *transfer_flag,
428 struct variable_field *fru_structure_data);
429
John Wang9e82ad12020-06-12 10:53:32 +0800430/** @brief Get FRU Record Table By Option
431 * @param[in] table - The source fru record table
432 * @param[in] table_size - Size of the source fru record table
433 * @param[out] record_table - Fru table fetched based on the input option
434 * @param[in/out] record_size - Size of the table fetched by fru record option
435 * @param[in] rsi - FRU record set identifier
436 * @param[in] rt - FRU record type
437 * @param[in] ft - FRU field type
438 */
439void get_fru_record_by_option(const uint8_t *table, size_t table_size,
440 uint8_t *record_table, size_t *record_size,
441 uint16_t rsi, uint8_t rt, uint8_t ft);
Sridevi Ramesh9cb05bd2021-05-31 08:37:33 -0500442/* SetFruRecordTable */
443
444/** @brief Decode SetFruRecordTable request data
445 *
446 * @param[in] msg - PLDM request message payload
447 * @param[in] payload_length - Length of request payload
448 * @param[out] data_transfer_handle - A handle used to identify a FRU Record
449 * table data transfer
450 * @param[out] transfer_flag - Flag to indicate what part of the transfer
451 * this request represents
452 * @param[out] fru_table_data - Struct variable_field, contains data specific
453 * to the fru record table and the length of table
454 * data
455 * @return pldm_completion_codes
456 */
457int decode_set_fru_record_table_req(const struct pldm_msg *msg,
458 size_t payload_length,
459 uint32_t *data_transfer_handle,
460 uint8_t *transfer_flag,
461 struct variable_field *fru_table_data);
462
463/** @brief Create a PLDM response message for SetFruRecordTable
464 *
465 * @param[in] instance_id - Message's instance id
466 * @param[in] completion_code - PLDM completion code
467 * @param[in] next_transfer_handle - handle to identify the next portion of the
468 * transfer
469 * @param[in] payload_length - Length of payload message
470 * @param[out] msg - Argument to capture the Message
471 */
472int encode_set_fru_record_table_resp(uint8_t instance_id,
473 uint8_t completion_code,
474 uint32_t next_data_transfer_handle,
475 size_t payload_length,
476 struct pldm_msg *msg);
John Wang9e82ad12020-06-12 10:53:32 +0800477
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530478#ifdef __cplusplus
479}
480#endif
481
482#endif