1 /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
2 #ifndef LIBPLDM_BIOS_TABLE_H
3 #define LIBPLDM_BIOS_TABLE_H
4 
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8 
9 #include <libpldm/bios.h>
10 
11 #include <stdbool.h>
12 #include <stddef.h>
13 #include <stdint.h>
14 struct variable_field;
15 
16 /** @struct pldm_bios_table_iter
17  *  structure representing bios table iterator
18  */
19 struct pldm_bios_table_iter;
20 
21 /** @brief Create a bios table iterator
22  *  @param[in] table - Pointer to table data
23  *  @param[in] length - Length of table data
24  *  @param[in] type - Type of pldm bios table
25  *  @return Iterator to the beginning on success. Returns NULL on failure.
26  */
27 struct pldm_bios_table_iter *
28 pldm_bios_table_iter_create(const void *table, size_t length,
29 			    enum pldm_bios_table_types type);
30 
31 /** @brief Release a bios table iterator
32  *  @param[in] iter - Pointer to bios table iterator
33  */
34 void pldm_bios_table_iter_free(struct pldm_bios_table_iter *iter);
35 
36 /** @brief Check if the iterator reaches the end of the bios table
37  *  @param[in] iter - Pointer to the bios table iterator
38  *  @return true if iterator reaches the end
39  *  @note *end* is a position after the last entry.
40  */
41 bool pldm_bios_table_iter_is_end(const struct pldm_bios_table_iter *iter);
42 
43 /** @brief Get iterator to next entry
44  *  @param[in] iter - Pointer the bios table iterator
45  */
46 void pldm_bios_table_iter_next(struct pldm_bios_table_iter *iter);
47 
48 /** @brief Get the bios table entry that the iterator points to
49  *  @param[in] iter - Pointer to the bios table iterator
50  *  @return Pointer to an entry in bios table
51  */
52 const void *pldm_bios_table_iter_value(struct pldm_bios_table_iter *iter);
53 
54 /** @brief Get the bios attribute table entry that the iterator points to
55  *  @param[in] iter - Pointer the bios attribute table iterator
56  *  @return Pointer to an entry in bios attribute table
57  */
58 static inline const struct pldm_bios_attr_table_entry *
pldm_bios_table_iter_attr_entry_value(struct pldm_bios_table_iter * iter)59 pldm_bios_table_iter_attr_entry_value(struct pldm_bios_table_iter *iter)
60 {
61 	return (const struct pldm_bios_attr_table_entry *)
62 		pldm_bios_table_iter_value(iter);
63 }
64 
65 /** @brief Get the bios string table entry that the iterator points to
66  *  @param[in] iter - Pointer the bios string table iterator
67  *  @return Pointer to an entry in bios string table
68  */
69 static inline const struct pldm_bios_string_table_entry *
pldm_bios_table_iter_string_entry_value(struct pldm_bios_table_iter * iter)70 pldm_bios_table_iter_string_entry_value(struct pldm_bios_table_iter *iter)
71 {
72 	return (const struct pldm_bios_string_table_entry *)
73 		pldm_bios_table_iter_value(iter);
74 }
75 
76 /** @brief Get the bios attribute value table entry that the iterator points to
77  *  @param[in] iter - Pointer the bios attribute value table iterator
78  *  @return Pointer to an entry in bios attribute value table
79  */
80 static inline const struct pldm_bios_attr_val_table_entry *
pldm_bios_table_iter_attr_value_entry_value(struct pldm_bios_table_iter * iter)81 pldm_bios_table_iter_attr_value_entry_value(struct pldm_bios_table_iter *iter)
82 {
83 	return (const struct pldm_bios_attr_val_table_entry *)
84 		pldm_bios_table_iter_value(iter);
85 }
86 
87 /** @brief Get the length of an entry in the BIOS String Table
88  *  @param[in] string_length - Length of string
89  *  @return Length of an entry in bytes
90  */
91 size_t pldm_bios_table_string_entry_encode_length(uint16_t string_length);
92 
93 /** @brief Create an entry of BIOS String Table and check the validity of the
94  * parameters
95  *
96  *  @param[out] entry - Pointer to a buffer to create an entry
97  *  @param[in] entry_length - Length of the buffer to create an entry
98  *  @param[in] str - String itself
99  *  @param[in] str_length - Length of the string
100  *  @return PLDM_SUCCESS on success, PLDM_ERROR_INVALID_DATA if entry or str are NULL, or
101  *          PLDM_ERROR_INVALID_LENGTH if entry_length is insufficient for encoding str. An
102  *          appropriate value for entry_length can be determined using
103  *          @ref pldm_bios_table_string_entry_encode_length
104  */
105 int pldm_bios_table_string_entry_encode(void *entry, size_t entry_length,
106 					const char *str, uint16_t str_length);
107 int pldm_bios_table_string_entry_encode_check(void *entry, size_t entry_length,
108 					      const char *str,
109 					      uint16_t str_length);
110 
111 /** @brief Get the string handle for the entry
112  *  @param[in] entry - Pointer to a bios string table entry
113  *  @return Handle to identify a string in the bios string table
114  */
115 uint16_t pldm_bios_table_string_entry_decode_handle(
116 	const struct pldm_bios_string_table_entry *entry);
117 
118 /** @brief Get the string length for the entry
119  *  @param[in] entry - Pointer to a bios string table entry
120  *  @return Length of string in bytes
121  */
122 uint16_t pldm_bios_table_string_entry_decode_string_length(
123 	const struct pldm_bios_string_table_entry *entry);
124 
125 /** @brief Get the string from the entry and check the validity of the
126  * parameters
127  *  @param[in] entry - Pointer to a bios string table entry
128  *  @param[out] buffer - Pointer to a buffer to store the string
129  *  @param[in] size - Size of the buffer to store the string
130  *  @return PLDM_SUCCESS on success, PLDM_ERROR_INVALID_DATA if entry or buffer are NULL, or
131  *          PLDM_ERROR_INVALID_LENGTH if size is insufficient for NUL termination. An
132  *          appropriate value for size can be determined using the expression
133  *          `pldm_bios_table_string_entry_decode_string_length(entry) + 1`. The provided size value
134  *          may be smaller than the entry's string, in which case the string placed in buffer will
135  *          be truncated (but still NUL terminated).
136  */
137 int pldm_bios_table_string_entry_decode_string(
138 	const struct pldm_bios_string_table_entry *entry, char *buffer,
139 	size_t size);
140 int pldm_bios_table_string_entry_decode_string_check(
141 	const struct pldm_bios_string_table_entry *entry, char *buffer,
142 	size_t size);
143 
144 /** @brief Find an entry in bios string table by string
145  *  @param[in] table - The BIOS String Table
146  *  @param[in] length - Length of the BIOS String Table
147  *  @param[in] str - String itself
148  *  @return Pointer to an entry in the bios string table
149  */
150 const struct pldm_bios_string_table_entry *
151 pldm_bios_table_string_find_by_string(const void *table, size_t length,
152 				      const char *str);
153 /** @brief Find an entry in bios string table by handle
154  *  @param[in] table - The BIOS String Table
155  *  @param[in] length - Length of the BIOS String Table
156  *  @param[in] handle - Handle to identify a string in the bios string table
157  *  @return Pointer to an entry in the bios string table
158  */
159 const struct pldm_bios_string_table_entry *
160 pldm_bios_table_string_find_by_handle(const void *table, size_t length,
161 				      uint16_t handle);
162 
163 /** @brief Get the attribute handle from the attribute table entry
164  *  @param[in] entry - Pointer to bios attribute table entry
165  *  @return handle to identify the attribute in the attribute table
166  */
167 uint16_t pldm_bios_table_attr_entry_decode_attribute_handle(
168 	const struct pldm_bios_attr_table_entry *entry);
169 
170 /** @brief Get the attribute type of the attribute table entry
171  *  @param[in] entry - Pointer to bios attribute table entry
172  *  @return Type of the attribute table entry
173  */
174 uint8_t pldm_bios_table_attr_entry_decode_attribute_type(
175 	const struct pldm_bios_attr_table_entry *entry);
176 
177 /** @brief Get the attribute name handle from the attribute table entry
178  *  @param[in] entry - Pointer to bios attribute table entry
179  *  @return handle to identify the name of the attribute, this handle points
180  *          to a string in the bios string table.
181  */
182 uint16_t pldm_bios_table_attr_entry_decode_string_handle(
183 	const struct pldm_bios_attr_table_entry *entry);
184 
185 /** @brief Find an entry in attribute table by handle
186  *  @param[in] table - The BIOS Attribute Table
187  *  @param[in] length - Length of the BIOS Attribute Table
188  *  @param[in] handle - handle to identify the attribute in the attribute table
189  *  @return Pointer to the entry
190  */
191 const struct pldm_bios_attr_table_entry *
192 pldm_bios_table_attr_find_by_handle(const void *table, size_t length,
193 				    uint16_t handle);
194 
195 /** @brief Find an entry in attribute table by string handle
196  *  @param[in] table - The BIOS Attribute Table
197  *  @param[in] length - Length of the BIOS Attribute Table
198  *  @param[in] handle - The string handle
199  *  @return Pointer to the entry
200  */
201 const struct pldm_bios_attr_table_entry *
202 pldm_bios_table_attr_find_by_string_handle(const void *table, size_t length,
203 					   uint16_t handle);
204 
205 /** @struct pldm_bios_table_attr_entry_enum_info
206  *
207  *  An auxiliary structure for passing parameters to @ref
208  * pldm_bios_table_attr_entry_enum_encode_check
209  *
210  */
211 struct pldm_bios_table_attr_entry_enum_info {
212 	uint16_t name_handle; //!< attribute name handle
213 	bool read_only;	      //!< indicate whether the attribute is read-only
214 	uint8_t pv_num;	      //!< number of possible values
215 	const uint16_t *pv_handle; //!< handles of possible values
216 	uint8_t def_num;	   //!< number of default values
217 	const uint8_t *def_index;  //!< indices of default values.
218 };
219 
220 /** @brief Get length that an attribute entry(type: enum) will take
221  *  @param[in] pv_num - Number of possible values
222  *  @param[in] def_num - Number of default values
223  *  @return The length that an entry(type: enum) will take
224  */
225 size_t pldm_bios_table_attr_entry_enum_encode_length(uint8_t pv_num,
226 						     uint8_t def_num);
227 
228 /** @brief Create an entry of BIOS Attribute Table (type: enum) and check the
229  * validity of the parameters
230  *  @param[out] entry - Pointer to a buffer to create an entry
231  *  @param[in] entry_length - Length of the buffer to create an entry
232  *  @param[in] info - Pointer to an auxiliary structure @ref
233  * pldm_bios_table_attr_entry_enum_info
234  *  @return PLDM_SUCCESS on success, otherwise PLDM_ERROR_INVALID_DATA if entry or info are NULL, or
235  *          PLDM_ERROR_INVALID_LENGTH if entry_length is insufficient to encode info. An appropriate
236  *          value for entry_length can be determined using @ref
237  *          pldm_bios_table_attr_entry_enum_encode_length.
238  */
239 int pldm_bios_table_attr_entry_enum_encode(
240 	void *entry, size_t entry_length,
241 	const struct pldm_bios_table_attr_entry_enum_info *info);
242 int pldm_bios_table_attr_entry_enum_encode_check(
243 	void *entry, size_t entry_length,
244 	const struct pldm_bios_table_attr_entry_enum_info *info);
245 
246 /** @brief Get the total number of possible values for the entry and check the
247  * validity of the parameters
248  *  @param[in] entry - Pointer to bios attribute table entry
249  *  @param[out] pv_num - Pointer to total number of possible values
250  *  @return PLDM_SUCCESS on success, PLDM_ERROR_INVALID_DATA if entry or pv_num are NULL, or
251  *          PLDM_ERROR_INVALID_DATA if entry is not a valid PLDM_BIOS_ENUMERATION
252  */
253 int pldm_bios_table_attr_entry_enum_decode_pv_num(
254 	const struct pldm_bios_attr_table_entry *entry, uint8_t *pv_num);
255 int pldm_bios_table_attr_entry_enum_decode_pv_num_check(
256 	const struct pldm_bios_attr_table_entry *entry, uint8_t *pv_num);
257 
258 /** @brief Get the total number of default values for the entry and check the
259  * validity of the parameters
260  *  @param[in] entry - Pointer to bios attribute table entry
261  *  @param[out] def_num - Pointer to total number of default values
262  *  @return PLDM_SUCCESS on success, otherwise PLDM_ERROR_INVALID_DATA if entry or def_num are NULL,
263  *          or entry is not of type PLDM_BIOS_ENUMERATION.
264  */
265 int pldm_bios_table_attr_entry_enum_decode_def_num(
266 	const struct pldm_bios_attr_table_entry *entry, uint8_t *def_num);
267 int pldm_bios_table_attr_entry_enum_decode_def_num_check(
268 	const struct pldm_bios_attr_table_entry *entry, uint8_t *def_num);
269 
270 /** @brief Get possible values string handles and check the validity of the
271  * parameters
272  *  @param[in] entry - Pointer to bios attribute table entry
273  *  @param[out] pv_hdls - Pointer to a buffer to store
274  * PossibleValuesStringHandles
275  *  @param[in] pv_num - Number of PossibleValuesStringHandles the buffer can
276  * store
277  *  @return PLDM_SUCCESS on success, otherwise PLDM_ERROR_INVALID_DATA if entry or pv_hdls are NULL,
278  *          or entry is not of type PLDM_BIOS_ENUMERATION. An appropriate value for pv_num can be
279  *          determined using @ref pldm_bios_table_attr_entry_enum_decode_pv_num_check. pv_num may be
280  *          less than the value provided by @ref
281  *          pldm_bios_table_attr_entry_enum_decode_pv_num_check, in which case only the first pv_num
282  *          handles will be decoded.
283  */
284 int pldm_bios_table_attr_entry_enum_decode_pv_hdls(
285 	const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
286 	uint8_t pv_num);
287 int pldm_bios_table_attr_entry_enum_decode_pv_hdls_check(
288 	const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
289 	uint8_t pv_num);
290 
291 /** @brief Get Indices of default values
292  *  @param[in] entry - Pointer to bios attribute table entry
293  *  @param[out] def_indices - Pointer to a buffer to store
294  *                            default value indices
295  *  @param[in] def_num - Number of DefaultValues the buffer can
296  *                       store
297  *  @return Number of default values decoded
298  */
299 uint8_t pldm_bios_table_attr_entry_enum_decode_def_indices(
300 	const struct pldm_bios_attr_table_entry *entry, uint8_t *def_indices,
301 	uint8_t def_num);
302 
303 /** @struct pldm_bios_table_attr_entry_string_info
304  *
305  *  An auxiliary structure for passing parameters to @ref
306  * pldm_bios_table_attr_entry_string_encode
307  *
308  */
309 struct pldm_bios_table_attr_entry_string_info {
310 	uint16_t name_handle;	//!< attribute name handle
311 	bool read_only;		//!< indicate whether the attribute is read-only
312 	uint8_t string_type;	//!< The type of the string
313 	uint16_t min_length;	//!< The minimum length of the string in bytes
314 	uint16_t max_length;	//!< The maximum length of the string in bytes
315 	uint16_t def_length;	//!< The length of the default string in bytes
316 	const char *def_string; //!< The default string itself
317 };
318 
319 /** @brief Check fields in @ref pldm_bios_table_attr_entry_string_info
320  *  @param[in] info - Pointer to the pldm_bios_table_attr_entry_string_info
321  *  @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
322  * memory
323  *  @return pldm_completion_codes
324  */
325 int pldm_bios_table_attr_entry_string_info_check(
326 	const struct pldm_bios_table_attr_entry_string_info *info,
327 	const char **errmsg);
328 
329 /** @brief Get length that an attribute entry(type: string) will take
330  *  @param[in] def_str_len - Length of default string
331  *  @return The length that an entry(type: string) will take
332  */
333 size_t pldm_bios_table_attr_entry_string_encode_length(uint16_t def_str_len);
334 
335 /** @brief Create an entry of BIOS Attribute Table (type: string) and check the
336  * validity of the parameters
337  *  @param[out] entry - Pointer to a buffer to create an entry
338  *  @param[in] entry_length - Length of the buffer to create an entry
339  *  @param[in] info - Pointer to an auxiliary structure @ref
340  * pldm_bios_table_attr_entry_string_info
341  *  @return PLDM_SUCCESS on success, PLDM_ERROR_INVALID_DATA if entry or info are NULL or info
342  *          contains logically inconsistent data, or PLDM_ERROR_INVALID_LENGTH if entry_length is
343  *          not sufficient to encode info. An appropriate value for entry_length can be determined
344  *          using @ref pldm_bios_table_attr_entry_string_encode_length
345  */
346 int pldm_bios_table_attr_entry_string_encode(
347 	void *entry, size_t entry_length,
348 	const struct pldm_bios_table_attr_entry_string_info *info);
349 int pldm_bios_table_attr_entry_string_encode_check(
350 	void *entry, size_t entry_length,
351 	const struct pldm_bios_table_attr_entry_string_info *info);
352 
353 /** @brief Get the length of default string in bytes for the entry and check the
354  * validity of the parameters
355  *  @param[in] entry - Pointer to bios attribute table entry
356  *  @param[out] def_string_length Pointer to length of default string in bytes
357  *  @return PLDM_SUCCESS on success, otherwise PLDM_ERROR_INVALID_DATA if entry or def_string_length
358  *          are NULL, or entry is not of type PLDM_BIOS_STRING
359  */
360 int pldm_bios_table_attr_entry_string_decode_def_string_length(
361 	const struct pldm_bios_attr_table_entry *entry,
362 	uint16_t *def_string_length);
363 int pldm_bios_table_attr_entry_string_decode_def_string_length_check(
364 	const struct pldm_bios_attr_table_entry *entry,
365 	uint16_t *def_string_length);
366 
367 /** @brief Get the type of string of bios attribute table entry
368  *  @param[in] entry - Pointer to bios attribute table entry
369  *  @return Type of the string
370  */
371 uint8_t pldm_bios_table_attr_entry_string_decode_string_type(
372 	const struct pldm_bios_attr_table_entry *entry);
373 
374 /** @brief Get maximum length of the string from a bios attribute table entry in
375  * bytes
376  *  @param[in] entry - Pointer to a bios attribute table entry
377  *  @return Maximum length of the string
378  */
379 uint16_t pldm_bios_table_attr_entry_string_decode_max_length(
380 	const struct pldm_bios_attr_table_entry *entry);
381 
382 /** @brief Get minimum length of the string from a bios attribute table entry in
383  * bytes
384  *  @param[in] entry - Pointer to a bios attribute table entry
385  *  @return Minimum length of the string
386  */
387 uint16_t pldm_bios_table_attr_entry_string_decode_min_length(
388 	const struct pldm_bios_attr_table_entry *entry);
389 
390 /** @brief Get the default string from a bios attribute table entry
391  *  @param[out] buffer - Pointer to a buffer to store the string
392  *  @param[in] size - Size of the buffer to store the string
393  *  @return Length of the string decoded
394  */
395 uint16_t pldm_bios_table_attr_entry_string_decode_def_string(
396 	const struct pldm_bios_attr_table_entry *entry, char *buffer,
397 	size_t size);
398 
399 /** @struct pldm_bios_table_attr_entry_integer_info
400  *
401  *  An auxiliary structure for passing parameters to @ref
402  * pldm_bios_table_attr_entry_integer_encode
403  *
404  */
405 struct pldm_bios_table_attr_entry_integer_info {
406 	uint16_t name_handle; //!< attribute name handle
407 	bool read_only;	      //!< indicate whether the attribute is read-only
408 	uint64_t lower_bound; //!< The lower bound on the integer value
409 	uint64_t upper_bound; //!< The upper bound on the integer value
410 	uint32_t scalar_increment; //!< The scalar value that is used for the
411 				   //!< increments to this integer
412 	uint64_t default_value;	   //!< The default value of the integer
413 };
414 
415 /** @brief Check fields in @ref pldm_bios_table_attr_entry_integer_info
416  *  @param[in] info - Pointer to the pldm_bios_table_attr_entry_integer_info
417  *  @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
418  * memory
419  *  @return pldm_completion_codes
420  */
421 int pldm_bios_table_attr_entry_integer_info_check(
422 	const struct pldm_bios_table_attr_entry_integer_info *info,
423 	const char **errmsg);
424 
425 /** @brief Get length that an attribute entry(type: integer) will take
426  *  @return The length that an entry(type: integer) will take
427  */
428 size_t pldm_bios_table_attr_entry_integer_encode_length(void);
429 
430 /** @brief Create an entry of BIOS Attribute Table (type: integer) and check the
431  * validity of the parameters
432  *  @param[out] entry - Pointer to a buffer to create an entry
433  *  @param[in] entry_length - Length of the buffer to create an entry
434  *  @param[in] info - Pointer to an auxiliary structure @ref
435  * pldm_bios_table_attr_entry_integer_info
436  *  @return PLDM_SUCCESS on success. PLDM_ERROR_INVALID_DATA if entry or info are null, or the data
437  *          in info is not logically consistent. PLDM_ERROR_INVALID_LENGTH if entry_length lacks
438  *          capacity to encode the attribute.
439  */
440 int pldm_bios_table_attr_entry_integer_encode(
441 	void *entry, size_t entry_length,
442 	const struct pldm_bios_table_attr_entry_integer_info *info);
443 int pldm_bios_table_attr_entry_integer_encode_check(
444 	void *entry, size_t entry_length,
445 	const struct pldm_bios_table_attr_entry_integer_info *info);
446 
447 /** @brief Decode the specific fields(integer) of attribute table entry
448  *  @param[in] entry - Pointer to an entry of attribute table
449  *  @param[out] lower - The lower bound on the integer value
450  *  @param[out] upper - The upper bound on the integer value
451  *  @param[out] scalar - The scalar value that is used for the increments to
452  *                       this integer
453  *  @param[out] def - The default value of the integer
454  */
455 void pldm_bios_table_attr_entry_integer_decode(
456 	const struct pldm_bios_attr_table_entry *entry, uint64_t *lower,
457 	uint64_t *upper, uint32_t *scalar, uint64_t *def);
458 
459 /** @brief Get the attribute handle from the attribute value table entry
460  *  @param[in] entry - Pointer to bios attribute value table entry
461  *  @return handle to identify the attribute in the attribute value table
462  */
463 uint16_t pldm_bios_table_attr_value_entry_decode_attribute_handle(
464 	const struct pldm_bios_attr_val_table_entry *entry);
465 
466 /** @brief Get the attribute type from the attribute value table entry
467  *  @param[in] entry - Pointer to bios attribute value table entry
468  *  @return Type of the attribute value entry
469  */
470 uint8_t pldm_bios_table_attr_value_entry_decode_attribute_type(
471 	const struct pldm_bios_attr_val_table_entry *entry);
472 
473 /** @brief Get length that an attribute value entry(type: enum) will take
474  *  @param[in] count - Total number of current values for this enumeration
475  *  @return The length that an entry(type: enum) will take
476  */
477 size_t pldm_bios_table_attr_value_entry_encode_enum_length(uint8_t count);
478 
479 /** @brief Get number of current values for the enum entry
480  *  @param[in] entry - Pointer to bios attribute value table entry
481  *  @return Total number of current values for this enumeration
482  */
483 uint8_t pldm_bios_table_attr_value_entry_enum_decode_number(
484 	const struct pldm_bios_attr_val_table_entry *entry);
485 
486 /** @brief Get CurrentValueStringHandleIndex
487  *  @param[in] entry - Pointer to bios attribute value table entry
488  *  @param[in, out] handles - Pointer to a buffer to store
489  *                            CurrentValueStringHandleIndex
490  *  @param[in] number - Number of PossibleValuesStringHandles expected
491  *  @return Number of CurrentValueStringHandleIndex decoded.
492  */
493 uint8_t pldm_bios_table_attr_value_entry_enum_decode_handles(
494 	const struct pldm_bios_attr_val_table_entry *entry, uint8_t *handles,
495 	uint8_t number);
496 
497 /** @brief Create an attribute value entry(type: enum) and check the validity of
498  * the parameters
499  *  @param[out] entry - Pointer to bios attribute value entry
500  *  @param[in] entry_length - Length of attribute value entry
501  *  @param[in] attr_handle - This handle points to an attribute in the
502  *  BIOS Attribute Value Table.
503  *  @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
504  * Table
505  *  @param[in] count - Total number of current values for this enum attribute
506  *  @param[in] handle_indexes - Index into the array(provided in the BIOS
507  * Attribute Table) of the possible values of string handles for this attribute.
508  *  @return PLDM_SUCCESS on success. PLDM_ERROR_INVALID_DATA if entry or handles are NULL, or if
509  *          attr_type is not a PLDM_BIOS_ENUMERATION. PLDM_ERROR_INVALID_LENGTH if entry_length
510  *          lacks capacity to encode handles into entry.
511  */
512 int pldm_bios_table_attr_value_entry_encode_enum(
513 	void *entry, size_t entry_length, uint16_t attr_handle,
514 	uint8_t attr_type, uint8_t count, const uint8_t *handles);
515 int pldm_bios_table_attr_value_entry_encode_enum_check(
516 	void *entry, size_t entry_length, uint16_t attr_handle,
517 	uint8_t attr_type, uint8_t count, const uint8_t *handles);
518 
519 /** @brief Get length that an attribute value entry(type: string) will take
520  *  @param[in] string_length - Length of the current string in byte, 0 indicates
521  *  that the current string value is not set.
522  *  @return The length that an entry(type: string) will take
523  */
524 size_t
525 pldm_bios_table_attr_value_entry_encode_string_length(uint16_t string_length);
526 
527 /** @brief Get length of the current string in bytes
528  *  @param [in] entry - Pointer to bios attribute value table entry
529  *  @return The length of the current string in bytes
530  */
531 uint16_t pldm_bios_table_attr_value_entry_string_decode_length(
532 	const struct pldm_bios_attr_val_table_entry *entry);
533 
534 /** @brief Get Current String Itself
535  *  @param[in] entry - Pointer to bios attribute value table entry
536  *  @param[in, out] current_string - Struct variable_field, contains a pointer
537  *                                   to the CurrentString field in the buffer of
538  *                                    \p entry, \p entry must be valid
539  *                                    when \p current_string is used.
540  */
541 void pldm_bios_table_attr_value_entry_string_decode_string(
542 	const struct pldm_bios_attr_val_table_entry *entry,
543 	struct variable_field *current_string);
544 
545 /** @brief Create an attribute value entry(type: string) and check the validity
546  * of the parameters
547  *  @param[out] entry - Pointer to bios attribute value entry
548  *  @param[in] entry_length - Length of attribute value entry
549  *  @param[in] attr_handle - This handle points to an attribute in the
550  *  BIOS Attribute Value Table.
551  *  @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
552  * Table
553  *  @param[in] string_length - Length of current string in bytes. 0 indicates
554  * that the current string value is not set.
555  *  @param[in] string - The current string itself
556  *  @return PLDM_SUCCESS on success. PLDM_ERROR_INVALID_DATA if entry is NULL, str is NULL while
557  *  	    str_length is non-zero, or attr_type is not PLDM_BIOS_STRING. PLDM_ERROR_INVALID_LENGTH
558  *  	    if entry_length lacks capacity to encode str into entry.
559  */
560 int pldm_bios_table_attr_value_entry_encode_string(
561 	void *entry, size_t entry_length, uint16_t attr_handle,
562 	uint8_t attr_type, uint16_t str_length, const char *string);
563 int pldm_bios_table_attr_value_entry_encode_string_check(
564 	void *entry, size_t entry_length, uint16_t attr_handle,
565 	uint8_t attr_type, uint16_t str_length, const char *string);
566 
567 /** @brief Get length that an attribute value entry(type: integer) will take
568  *  @return The length that an entry(type: integer) will take
569  */
570 size_t pldm_bios_table_attr_value_entry_encode_integer_length(void);
571 
572 /** @brief Get current values for the integer entry
573  *  @param[in] entry - Pointer to bios attribute value table entry
574  *  @return Current Value
575  */
576 uint64_t pldm_bios_table_attr_value_entry_integer_decode_cv(
577 	const struct pldm_bios_attr_val_table_entry *entry);
578 
579 /** @brief Create an attribute value entry(type: integer) and check the validity
580  * of the parameters
581  *  @param[out] entry - Pointer to bios attribute value entry
582  *  @param[in] entry_length - Length of attribute value entry
583  *  @param[in] attr_handle - This handle points to an attribute in the
584  *  BIOS Attribute Value Table.
585  *  @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
586  * Table
587  *  @param[in] cv - Current Value
588  *  @return PLDM_SUCCESS on success. PLDM_ERROR_INVALID_DATA if entry is NULL or attr_type is not
589  *  	    PLDM_BIOS_INTEGER. PLDM_ERROR_INVALID_LENGTH if entry_length lacks capacity to encode cv
590  *  	    in entry.
591  */
592 int pldm_bios_table_attr_value_entry_encode_integer(void *entry,
593 						    size_t entry_length,
594 						    uint16_t attr_handle,
595 						    uint8_t attr_type,
596 						    uint64_t cv);
597 int pldm_bios_table_attr_value_entry_encode_integer_check(void *entry,
598 							  size_t entry_length,
599 							  uint16_t attr_handle,
600 							  uint8_t attr_type,
601 							  uint64_t cv);
602 
603 /** @brief Get the handle from the attribute value entry
604  *  @param[in] entry - Pointer to bios attribute value entry
605  *  @return handle to identify the attribute in the attribute value table
606  */
607 uint16_t pldm_bios_table_attr_value_entry_decode_handle(
608 	const struct pldm_bios_attr_val_table_entry *entry);
609 
610 /** @brief Get the length of the attribute value entry
611  *  @param[in] entry - Pointer to bios attribute value entry
612  *  @return Length of the entry
613  */
614 size_t pldm_bios_table_attr_value_entry_length(
615 	const struct pldm_bios_attr_val_table_entry *entry);
616 
617 /** @brief Find an entry in attribute value table by handle
618  *  @param[in] table - The BIOS Attribute Value Table
619  *  @param[in] length - Length of the BIOS Attribute Value Table
620  *  @param[in] handle - handle to identify the attribute in the attribute value
621  * table
622  *  @return Pointer to the entry
623  */
624 const struct pldm_bios_attr_val_table_entry *
625 pldm_bios_table_attr_value_find_by_handle(const void *table, size_t length,
626 					  uint16_t handle);
627 
628 /** @brief Get the size of pad and checksum
629  *  @param[in] size_without_pad - Table size without pad
630  *  @return The size of pad and checksum
631  */
632 size_t pldm_bios_table_pad_checksum_size(size_t size_without_pad);
633 
634 /** @brief Append pad and checksum at the end of the table or return an error
635  *  @param[in,out] table - Pointer to a buffer of a bios table
636  *  @param[in] capacity - Size of the buffer of a bios table
637  *  @param[in,out] size - On input, the table size without pad and checksum, on output, the table
638  *  			  with the padding and checksum appended
639  *  @return PLDM_SUCCESS on success, PLDM_INVALID_DATA if table or size are NULL, or
640  *  	    PLDM_ERROR_INVALID_LENGTH if size lacks capacity to encode the padded checksum in the
641  *  	    buffer provided by table. The appropriate buffer capacity can be determined with the
642  *  	    help of @ref pldm_bios_table_pad_checksum_size
643  */
644 int pldm_bios_table_append_pad_checksum(void *table, size_t capacity,
645 					size_t *size);
646 int pldm_bios_table_append_pad_checksum_check(void *table, size_t capacity,
647 					      size_t *size);
648 
649 /** @brief Build a new table and update an entry
650  *  @param[in] src_table - Pointer to the source table
651  *  @param[in] src_length - Size of the source table
652  *  @param[out] dest_table - Pointer to the buffer of destination table
653  *  @param[in,out] dest_length - Buffer size of the destination table as input
654  *                               parameter and will be assigned the length of
655  *                               the new table, if the function returns
656  * 				 PLDM_SUCCESS
657  *  @param[in] entry - Pointer to an entry
658  *  @param[in] entry_length - Size of the entry
659  *  @return pldm_completion_codes
660  */
661 int pldm_bios_table_attr_value_copy_and_update(
662 	const void *src_table, size_t src_length, void *dest_table,
663 	size_t *dest_length, const void *entry, size_t entry_length);
664 
665 /** @brief Verify the crc value of the complete table
666  *  @param[in] table - Pointer to a buffer of a bios table
667  *  @param[in] size - Size of the buffer of a bios table
668  *  @return true: crc value is correct
669  */
670 bool pldm_bios_table_checksum(const uint8_t *table, size_t size);
671 
672 #ifdef __cplusplus
673 }
674 #endif
675 
676 #endif
677