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