blob: 37399371340aaf369f658df0d57b45ae59465951 [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
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053020
Christian Geddes3bdb3c22020-05-01 14:55:39 -050021#define FRU_TABLE_CHECKSUM_SIZE 4
22
John Wang9e82ad12020-06-12 10:53:32 +080023enum pldm_fru_completion_codes {
24 PLDM_FRU_DATA_STRUCTURE_TABLE_UNAVAILABLE = 0x85,
25};
26
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053027/** @brief PLDM FRU commands
28 */
29enum pldm_fru_commands {
30 PLDM_GET_FRU_RECORD_TABLE_METADATA = 0X01,
PriyangaRamasamy497665a2019-07-30 12:48:25 +053031 PLDM_GET_FRU_RECORD_TABLE = 0X02,
PriyangaRamasamyf3295be2019-07-23 12:18:40 +053032 PLDM_SET_FRU_RECORD_TABLE = 0X03,
33 PLDM_GET_FRU_RECORD_BY_OPTION = 0X04
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053034};
35
Tom Joseph93d68712020-01-07 10:24:41 +053036/** @brief FRU record types
37 */
38enum pldm_fru_record_type {
39 PLDM_FRU_RECORD_TYPE_GENERAL = 0X01,
40 PLDM_FRU_RECORD_TYPE_OEM = 0XFE,
41};
42
43/** @brief Encoding type for FRU fields
44 */
45enum pldm_fru_field_encoding {
46 PLDM_FRU_ENCODING_UNSPECIFIED = 0X00,
47 PLDM_FRU_ENCODING_ASCII = 0X01,
48 PLDM_FRU_ENCODING_UTF8 = 0X02,
49 PLDM_FRU_ENCODING_UTF16 = 0X03,
50 PLDM_FRU_ENCODING_UTF16LE = 0X04,
51 PLDM_FRU_ENCODING_UTF16BE = 0X05,
52};
53
54/** @brief FRU field types
55 */
56enum pldm_fru_field_type {
57 PLDM_FRU_FIELD_TYPE_CHASSIS = 0X01,
58 PLDM_FRU_FIELD_TYPE_MODEL = 0X02,
59 PLDM_FRU_FIELD_TYPE_PN = 0X03,
60 PLDM_FRU_FIELD_TYPE_SN = 0X04,
61 PLDM_FRU_FIELD_TYPE_MANUFAC = 0X05,
62 PLDM_FRU_FIELD_TYPE_MANUFAC_DATE = 0X06,
63 PLDM_FRU_FIELD_TYPE_VENDOR = 0X07,
64 PLDM_FRU_FIELD_TYPE_NAME = 0X08,
65 PLDM_FRU_FIELD_TYPE_SKU = 0X09,
66 PLDM_FRU_FIELD_TYPE_VERSION = 0X0A,
67 PLDM_FRU_FIELD_TYPE_ASSET_TAG = 0X0B,
68 PLDM_FRU_FIELD_TYPE_DESC = 0X0C,
69 PLDM_FRU_FIELD_TYPE_EC_LVL = 0X0D,
70 PLDM_FRU_FIELD_TYPE_OTHER = 0X0E,
71 PLDM_FRU_FIELD_TYPE_IANA = 0X0F,
72};
73
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053074/** @struct pldm_get_fru_record_table_metadata_resp
75 *
76 * Structure representing PLDM get FRU table metadata response.
77 */
78struct pldm_get_fru_record_table_metadata_resp {
79 uint8_t completion_code; //!< completion code
80 uint8_t fru_data_major_version; //!< The major version of the FRU Record
81 uint8_t fru_data_minor_version; //!< The minor version of the FRU Record
82 uint32_t
83 fru_table_maximum_size; //!< The size of the largest FRU Record data
84 uint32_t fru_table_length; //!< The total length of the FRU Record Table
85 uint16_t total_record_set_identifiers; //!< The total number of FRU
86 //!< Record Data structures
87 uint16_t
88 total_table_records; //!< The total number of records in the table
89 uint32_t
90 checksum; //!< The integrity checksum on the FRU Record Table data
91} __attribute__((packed));
92
PriyangaRamasamy497665a2019-07-30 12:48:25 +053093/** @struct pldm_get_fru_record_table_req
94 *
95 * Structure representing PLDM get FRU record table request.
96 */
97struct pldm_get_fru_record_table_req {
98 uint32_t data_transfer_handle;
99 uint8_t transfer_operation_flag;
100} __attribute__((packed));
101
102/** @struct pldm_get_fru_record_table_resp
103 *
104 * Structure representing PLDM get FRU record table response.
105 */
106struct pldm_get_fru_record_table_resp {
107 uint8_t completion_code;
108 uint32_t next_data_transfer_handle;
109 uint8_t transfer_flag;
110 uint8_t fru_record_table_data[1];
111} __attribute__((packed));
112
John Wang9fa87cf2020-06-10 17:53:40 +0800113struct pldm_get_fru_record_by_option_req {
114 uint32_t data_transfer_handle;
115 uint16_t fru_table_handle;
116 uint16_t record_set_identifier;
117 uint8_t record_type;
118 uint8_t field_type;
119 uint8_t transfer_op_flag;
120} __attribute__((packed));
121
122struct pldm_get_fru_record_by_option_resp {
123 uint8_t completion_code;
124 uint32_t next_data_transfer_handle;
125 uint8_t transfer_flag;
126 uint8_t fru_structure_data[1];
127} __attribute__((packed));
128
Tom Joseph93d68712020-01-07 10:24:41 +0530129/** @struct pldm_fru_record_tlv
130 *
131 * Structure representing each FRU field entry (type, length, value)
132 */
133struct pldm_fru_record_tlv {
134 uint8_t type;
135 uint8_t length;
136 uint8_t value[1];
137} __attribute__((packed));
138
139/** @struct pldm_fru_record_data_format
140 *
141 * Structure representing the FRU record data format
142 */
143struct pldm_fru_record_data_format {
144 uint16_t record_set_id;
145 uint8_t record_type;
146 uint8_t num_fru_fields;
147 uint8_t encoding_type;
148 struct pldm_fru_record_tlv tlvs[1];
149} __attribute__((packed));
150
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530151/* Requester */
152
153/* GetFRURecordTableMetadata */
154
155/** @brief Create a PLDM request message for GetFRURecordTableMetadata
156 *
157 * @param[in] instance_id - Message's instance id
158 * @param[in,out] msg - Message will be written to this
Christian Geddes3bdb3c22020-05-01 14:55:39 -0500159 * @param[in] payload_length - Length of the request message payload
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530160 * @return pldm_completion_codes
161 * @note Caller is responsible for memory alloc and dealloc of param
162 * 'msg.payload'
163 */
164int encode_get_fru_record_table_metadata_req(uint8_t instance_id,
Christian Geddes3bdb3c22020-05-01 14:55:39 -0500165 struct pldm_msg *msg,
166 size_t payload_length);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530167
168/** @brief Decode GetFruRecordTable response data
169 *
George Liu684a7162019-12-06 15:10:52 +0800170 * Note:
171 * * If the return value is not PLDM_SUCCESS, it represents a
172 * transport layer error.
173 * * If the completion_code value is not PLDM_SUCCESS, it represents a
174 * protocol layer error and all the out-parameters are invalid.
175 *
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530176 * @param[in] msg - Response message
177 * @param[in] payload_length - Length of response message payload
178 * @param[out] completion_code - Pointer to response msg's PLDM completion code
179 * @param[out] fru_data_major_version - Major version of the FRU Record
180 * @param[out] fru_data_minor_version - Minor version of the FRU Record
181 * @param[out] fru_table_maximum_size - Size of the largest FRU Record data
182 * @param[out] fru_table_length - Total length of the FRU Record Table
183 * @param[out] total_Record_Set_Identifiers - Total number of FRU Record Data
184 * structures
185 * @param[out] total_table_records - Total number of records in the table
186 * @param[out] checksum - integrity checksum on the FRU Record Table data
187 * @return pldm_completion_codes
188 */
189int decode_get_fru_record_table_metadata_resp(
190 const struct pldm_msg *msg, size_t payload_length, uint8_t *completion_code,
191 uint8_t *fru_data_major_version, uint8_t *fru_data_minor_version,
192 uint32_t *fru_table_maximum_size, uint32_t *fru_table_length,
193 uint16_t *total_record_set_identifiers, uint16_t *total_table_records,
194 uint32_t *checksum);
195
196/* Responder */
197
198/* GetFRURecordTableMetadata */
199
200/** @brief Create a PLDM response message for GetFRURecordTableMetadata
201 *
202 * @param[in] instance_id - Message's instance id
203 * @param[in] completion_code - PLDM completion code
204 * @param[in] fru_data_major_version - Major version of the FRU Record
205 * @param[in] fru_data_minor_version - Minor version of the FRU Record
206 * @param[in] fru_table_maximum_size - Size of the largest FRU Record data
207 * @param[in] fru_table_length - Total length of the FRU Record Table
208 * @param[in] total_Record_Set_Identifiers - Total number of FRU Record Data
209 * structures
210 * @param[in] total_table_records - Total number of records in the table
211 * @param[in] checksum - integrity checksum on the FRU Record Table data
212 * @param[in,out] msg - Message will be written to this
213 * @return pldm_completion_codes
214 * @note Caller is responsible for memory alloc and dealloc of param
215 * 'msg.payload'
216 */
217
218int encode_get_fru_record_table_metadata_resp(
219 uint8_t instance_id, uint8_t completion_code,
220 uint8_t fru_data_major_version, uint8_t fru_data_minor_version,
221 uint32_t fru_table_maximum_size, uint32_t fru_table_length,
222 uint16_t total_record_set_identifiers, uint16_t total_table_records,
223 uint32_t checksum, struct pldm_msg *msg);
224
PriyangaRamasamy497665a2019-07-30 12:48:25 +0530225/* GetFruRecordTable */
226
227/** @brief Decode GetFruRecordTable request data
228 *
229 * @param[in] msg - PLDM request message payload
230 * @param[in] payload_length - Length of request payload
231 * @param[out] data_transfer_handle - A handle, used to identify a FRU Record
232 * Table data transfer
233 * @param[out] transfer_operation_flag - A flag that indicates whether this is
234 * the start of the transfer
235 * @return pldm_completion_codes
236 */
237int decode_get_fru_record_table_req(const struct pldm_msg *msg,
238 size_t payload_length,
239 uint32_t *data_transfer_handle,
240 uint8_t *transfer_operation_flag);
241
242/** @brief Create a PLDM response message for GetFruRecordTable
243 *
244 * @param[in] instance_id - Message's instance id
245 * @param[in] completion_code - PLDM completion code
246 * @param[in] next_data_transfer_handle - A handle that is used to identify the
247 * next portion of the transfer
248 * @param[in] transfer_flag - The transfer flag that indicates what part of the
249 * transfer this response represents
250 * @param[in,out] msg - Message will be written to this
251 * @return pldm_completion_codes
252 * @note Caller is responsible for memory alloc and dealloc of param 'msg',
253 * and for appending the FRU table to the msg.
254 */
255int encode_get_fru_record_table_resp(uint8_t instance_id,
256 uint8_t completion_code,
257 uint32_t next_data_transfer_handle,
258 uint8_t transfer_flag,
259 struct pldm_msg *msg);
John Wang9fa87cf2020-06-10 17:53:40 +0800260
261/* GetFRURecordByOption */
262
263/** @brief Decode GetFRURecordByOption request data
264 *
265 * @param[in] msg - PLDM request message payload
266 * @param[in] payload_length - Length of request payload
267 * @param[out] data_transfer_handle - A handle, used to identify a FRU Record
268 * Table data transfer
269 * @param[out] fru_table_handle - A handle, used to identify a FRU DATA
270 * records
271 * @param[out] record_set_identifier - FRU record set identifier
272 * @param[out] record_type - FRU record type
273 * @param[out] field_type - FRU field type
274 * @param[out] transfer_op_flag - A flag that indicates whether this is
275 * the start of the transfer
276 * @return pldm_completion_codes
277 */
278int decode_get_fru_record_by_option_req(
279 const struct pldm_msg *msg, size_t payload_length,
280 uint32_t *data_transfer_handle, uint16_t *fru_table_handle,
281 uint16_t *record_set_identifier, uint8_t *record_type, uint8_t *field_type,
282 uint8_t *transfer_op_flag);
283
284/** @brief Encode GetFRURecordByOption response data
285 *
286 * @param[in] instance_id - Message's instance id
287 * @param[in] completion_code - PLDM completion code
288 * @param[in] next_data_transfer_handle - A handle that is used to identify the
289 * next portion of the transfer
290 * @param[in] transfer_flag - The transfer flag that indicates what part of the
291 * transfer this response represents
292 * @param[in] fru_structure_data - FRU Structure Data
293 * @param[in] data_size - Size of FRU Structrue Data
294 * @param[in,out] msg - Message will be written to this
295 * @return pldm_completion_codes
296 * @note Caller is responsible for memory alloc and dealloc of param 'msg',
297 * and for appending the FRU table to the msg.
298 */
299int encode_get_fru_record_by_option_resp(uint8_t instance_id,
300 uint8_t completion_code,
301 uint32_t next_data_transfer_handle,
302 uint8_t transfer_flag,
303 const void *fru_structure_data,
304 size_t data_size, struct pldm_msg *msg,
305 size_t payload_length);
306
PriyangaRamasamyf3295be2019-07-23 12:18:40 +0530307/* Requester */
308
309/* GetFruRecordTable */
310
311/** @brief Create a PLDM request message for GetFruRecordTable
312 *
313 * @param[in] instance_id - Message's instance id
314 * @param[in] data_transfer_handle - A handle, used to identify a FRU Record
315 * Table data transfer
316 * @param[in] transfer_operation_flag - A flag that indicates whether this is
317 * the start of the transfer
318 * @param[in,out] msg - Message will be written to this
319 * @param[in] payload_length - Length of request message payload
320 * @return pldm_completion_codes
321 * @note Caller is responsible for memory alloc and dealloc of param
322 * 'msg.payload'
323 */
324
325int encode_get_fru_record_table_req(uint8_t instance_id,
326 uint32_t data_transfer_handle,
327 uint8_t transfer_operation_flag,
328 struct pldm_msg *msg,
329 size_t payload_length);
330
331/** @brief Decode GetFruRecordTable response data
332 *
333 * @param[in] msg - Response message
334 * @param[in] payload_length - Length of response message payload
335 * @param[out] completion_code - Pointer to response msg's PLDM completion code
336 * @param[out] next_data_transfer_handle - A handle used to identify the next
337 * portion of the transfer
338 * @param[out] transfer_flag - The transfer flag that indicates what part of
339 * the transfer this response represents
340 * @param[out] fru_record_table_data - This data is a portion of the overall
341 * FRU Record Table
342 * @param[out] fru_record_table_length - Length of the FRU record table data
343 * @return pldm_completion_codes
344 */
345
346int decode_get_fru_record_table_resp(
347 const struct pldm_msg *msg, size_t payload_length, uint8_t *completion_code,
348 uint32_t *next_data_transfer_handle, uint8_t *transfer_flag,
349 uint8_t *fru_record_table_data, size_t *fru_record_table_length);
PriyangaRamasamy497665a2019-07-30 12:48:25 +0530350
Tom Joseph93d68712020-01-07 10:24:41 +0530351/** @brief Encode the FRU record in the FRU table
352 *
353 * @param[in/out] fru_table - Pointer to the FRU table
354 * @param[in] total_size - The size of the table,including the size of FRU
355 * record to be added to the table.
356 * @param[in/out] curr_size - The size of the table, excluding the size of FRU
357 * record to be added to the table.
358 * @param[in] record_set_id - FRU record set identifier
359 * @param[in] record_type - FRU record type
360 * @param[in] num_frus - Number of FRU fields
361 * @param[in] encoding - Encoding type for FRU fields
362 * @param[in] tlvs - Pointer to the buffer with all the FRU fields
363 * @param[in] tlvs_size - Size of the buffer with all the FRU fields
364 *
365 * @return pldm_completion_codes
366 */
367int encode_fru_record(uint8_t *fru_table, size_t total_size, size_t *curr_size,
368 uint16_t record_set_id, uint8_t record_type,
369 uint8_t num_frus, uint8_t encoding, uint8_t *tlvs,
370 size_t tlvs_size);
371
John Wang9fa87cf2020-06-10 17:53:40 +0800372/* GetFRURecordByOption */
373
374/** @brief Create a PLDM request message for GetFRURecordByOption
375 *
376 * @param[in] instance_id - Message's instance id
377 * @param[in] data_transfer_handle - A handle, used to identify a FRU Record
378 * Table data transfer
379 * @param[in] fru_table_handle - A handle, used to identify a FRU DATA records
380 * @param[in] record_set_identifier - FRU record set identifier
381 * @param[in] record_type - FRU record type
382 * @param[in] field_type - FRU field type
383 * @param[in] transfer_op_flag - A flag that indicates whether this is
384 * the start of the transfer
385 * @param[in,out] msg - Message will be written to this
386 * @param[in] payload_length - Length of request message payload
387 * @return pldm_completion_codes
388 * @note Caller is responsible for memory alloc and dealloc of param
389 * 'msg.payload'
390 */
391int encode_get_fru_record_by_option_req(
392 uint8_t instance_id, uint32_t data_transfer_handle,
393 uint16_t fru_table_handle, uint16_t record_set_identifier,
394 uint8_t record_type, uint8_t field_type, uint8_t transfer_op_flag,
395 struct pldm_msg *msg, size_t payload_length);
396
397/** @brief Decode GetFRURecordByOption response data
398 *
399 * @param[in] msg - Response message
400 * @param[in] payload_length - Length of response message payload
401 * @param[out] completion_code - Pointer to response msg's PLDM completion code
402 * @param[out] next_data_transfer_handle - A handle used to identify the next
403 * portion of the transfer
404 * @param[out] transfer_flag - The transfer flag that indicates what part of
405 * the transfer this response represents
406 * @param[out] fru_structure_data - FRU Structure Data
407 * @return pldm_completion_codes
408 */
409int decode_get_fru_record_by_option_resp(
410 const struct pldm_msg *msg, size_t payload_length, uint8_t *completion_code,
411 uint32_t *next_transfer_handle, uint8_t *transfer_flag,
412 struct variable_field *fru_structure_data);
413
John Wang9e82ad12020-06-12 10:53:32 +0800414/** @brief Get FRU Record Table By Option
415 * @param[in] table - The source fru record table
416 * @param[in] table_size - Size of the source fru record table
417 * @param[out] record_table - Fru table fetched based on the input option
418 * @param[in/out] record_size - Size of the table fetched by fru record option
419 * @param[in] rsi - FRU record set identifier
420 * @param[in] rt - FRU record type
421 * @param[in] ft - FRU field type
422 */
423void get_fru_record_by_option(const uint8_t *table, size_t table_size,
424 uint8_t *record_table, size_t *record_size,
425 uint16_t rsi, uint8_t rt, uint8_t ft);
426
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530427#ifdef __cplusplus
428}
429#endif
430
431#endif