blob: 0239f3d0ef06af86b356ef17af49ebb6b494cc94 [file] [log] [blame]
Andrew Jeffery4edb7082023-04-05 19:09:52 +09301#ifndef LIBPLDM_BIOS_TABLE_H
2#define LIBPLDM_BIOS_TABLE_H
Andrew Jeffery9c766792022-08-10 23:12:49 +09303
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include "bios.h"
Andrew Jeffery9c766792022-08-10 23:12:49 +09309#include <stdbool.h>
10#include <stddef.h>
11#include <stdint.h>
Manojkiran Eda9a8e4972022-11-28 16:38:21 +053012struct variable_field;
Andrew Jeffery9c766792022-08-10 23:12:49 +093013
14/** @struct pldm_bios_table_iter
15 * structure representing bios table iterator
16 */
17struct pldm_bios_table_iter;
18
19/** @brief Create a bios table iterator
20 * @param[in] table - Pointer to table data
21 * @param[in] length - Length of table data
22 * @param[in] type - Type of pldm bios table
Andrew Jeffery757e81a2023-06-28 12:15:59 +093023 * @return Iterator to the beginning on success. Returns NULL on failure.
Andrew Jeffery9c766792022-08-10 23:12:49 +093024 */
25struct pldm_bios_table_iter *
26pldm_bios_table_iter_create(const void *table, size_t length,
27 enum pldm_bios_table_types type);
28
29/** @brief Release a bios table iterator
30 * @param[in] iter - Pointer to bios table iterator
31 */
32void pldm_bios_table_iter_free(struct pldm_bios_table_iter *iter);
33
34/** @brief Check if the iterator reaches the end of the bios table
35 * @param[in] iter - Pointer to the bios table iterator
36 * @return true if iterator reaches the end
37 * @note *end* is a position after the last entry.
38 */
39bool pldm_bios_table_iter_is_end(const struct pldm_bios_table_iter *iter);
40
41/** @brief Get iterator to next entry
42 * @param[in] iter - Pointer the bios table iterator
43 */
44void pldm_bios_table_iter_next(struct pldm_bios_table_iter *iter);
45
46/** @brief Get the bios table entry that the iterator points to
47 * @param[in] iter - Pointer to the bios table iterator
48 * @return Pointer to an entry in bios table
49 */
50const void *pldm_bios_table_iter_value(struct pldm_bios_table_iter *iter);
51
52/** @brief Get the bios attribute table entry that the iterator points to
53 * @param[in] iter - Pointer the bios attribute table iterator
54 * @return Pointer to an entry in bios attribute table
55 */
56static inline const struct pldm_bios_attr_table_entry *
57pldm_bios_table_iter_attr_entry_value(struct pldm_bios_table_iter *iter)
58{
59 return (const struct pldm_bios_attr_table_entry *)
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093060 pldm_bios_table_iter_value(iter);
Andrew Jeffery9c766792022-08-10 23:12:49 +093061}
62
63/** @brief Get the bios string table entry that the iterator ponit to
64 * @param[in] iter - Pointer the bios string table iterator
65 * @return Pointer to an entry in bios string table
66 */
67static inline const struct pldm_bios_string_table_entry *
68pldm_bios_table_iter_string_entry_value(struct pldm_bios_table_iter *iter)
69{
70 return (const struct pldm_bios_string_table_entry *)
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093071 pldm_bios_table_iter_value(iter);
Andrew Jeffery9c766792022-08-10 23:12:49 +093072}
73
74/** @brief Get the bios attribute value table entry that the iterator ponit to
75 * @param[in] iter - Pointer the bios attribute value table iterator
76 * @return Pointer to an entry in bios attribute value table
77 */
78static inline const struct pldm_bios_attr_val_table_entry *
79pldm_bios_table_iter_attr_value_entry_value(struct pldm_bios_table_iter *iter)
80{
81 return (const struct pldm_bios_attr_val_table_entry *)
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093082 pldm_bios_table_iter_value(iter);
Andrew Jeffery9c766792022-08-10 23:12:49 +093083}
84
85/** @brief Get the length of an entry in the BIOS String Table
86 * @param[in] string_length - Length of string
87 * @return Length of an entry in bytes
88 */
89size_t pldm_bios_table_string_entry_encode_length(uint16_t string_length);
90
Andrew Jeffery9c766792022-08-10 23:12:49 +093091/** @brief Create an entry of BIOS String Table and check the validity of the
92 * parameters
Andrew Jeffery91f4b542023-06-13 20:59:51 +093093 *
Andrew Jeffery9c766792022-08-10 23:12:49 +093094 * @param[out] entry - Pointer to a buffer to create an entry
95 * @param[in] entry_length - Length of the buffer to create an entry
96 * @param[in] str - String itself
97 * @param[in] str_length - Length of the string
Andrew Jeffery91f4b542023-06-13 20:59:51 +093098 * @return PLDM_SUCCESS on success, PLDM_ERROR_INVALID_DATA if entry or str are NULL, or
99 * PLDM_ERROR_INVALID_LENGTH if entry_length is insufficient for encoding str. An
100 * appropriate value for entry_length can be determined using
101 * @ref pldm_bios_table_string_entry_encode_length
Andrew Jeffery9c766792022-08-10 23:12:49 +0930102 */
103int pldm_bios_table_string_entry_encode_check(void *entry, size_t entry_length,
104 const char *str,
105 uint16_t str_length);
106
107/** @brief Get the string handle for the entry
108 * @param[in] entry - Pointer to a bios string table entry
109 * @return Handle to identify a string in the bios string table
110 */
111uint16_t pldm_bios_table_string_entry_decode_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930112 const struct pldm_bios_string_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930113
114/** @brief Get the string length for the entry
115 * @param[in] entry - Pointer to a bios string table entry
116 * @return Length of string in bytes
117 */
118uint16_t pldm_bios_table_string_entry_decode_string_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930119 const struct pldm_bios_string_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930120
Andrew Jeffery9c766792022-08-10 23:12:49 +0930121/** @brief Get the string from the entry and check the validity of the
122 * parameters
123 * @param[in] entry - Pointer to a bios string table entry
124 * @param[out] buffer - Pointer to a buffer to store the string
125 * @param[in] size - Size of the buffer to store the string
Andrew Jeffery23250312023-06-13 21:07:46 +0930126 * @return PLDM_SUCCESS on success, PLDM_ERROR_INVALID_DATA if entry or buffer are NULL, or
Andrew Jeffery98c1e692023-06-14 14:41:19 +0930127 * PLDM_ERROR_INVALID_LENGTH if size is insufficient for NUL termination. An
Andrew Jeffery23250312023-06-13 21:07:46 +0930128 * appropriate value for size can be determined using the expression
Andrew Jeffery98c1e692023-06-14 14:41:19 +0930129 * `pldm_bios_table_string_entry_decode_string_length(entry) + 1`. The provided size value
130 * may be smaller than the entry's string, in which case the string placed in buffer will
131 * be truncated (but still NUL terminated).
Andrew Jeffery9c766792022-08-10 23:12:49 +0930132 */
133int pldm_bios_table_string_entry_decode_string_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930134 const struct pldm_bios_string_table_entry *entry, char *buffer,
135 size_t size);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930136
137/** @brief Find an entry in bios string table by string
138 * @param[in] table - The BIOS String Table
139 * @param[in] length - Length of the BIOS String Table
140 * @param[in] str - String itself
141 * @return Pointer to an entry in the bios string table
142 */
143const struct pldm_bios_string_table_entry *
144pldm_bios_table_string_find_by_string(const void *table, size_t length,
145 const char *str);
146/** @brief Find an entry in bios string table by handle
147 * @param[in] table - The BIOS String Table
148 * @param[in] length - Length of the BIOS String Table
149 * @param[in] handle - Handle to identify a string in the bios string table
150 * @return Pointer to an entry in the bios string table
151 */
152const struct pldm_bios_string_table_entry *
153pldm_bios_table_string_find_by_handle(const void *table, size_t length,
154 uint16_t handle);
155
156/** @brief Get the attribute handle from the attribute table entry
157 * @param[in] entry - Pointer to bios attribute table entry
158 * @return handle to identify the attribute in the attribute table
159 */
160uint16_t pldm_bios_table_attr_entry_decode_attribute_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930161 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930162
163/** @brief Get the attribute type of the attribute table entry
164 * @param[in] entry - Pointer to bios attribute table entry
165 * @return Type of the attribute table entry
166 */
167uint8_t pldm_bios_table_attr_entry_decode_attribute_type(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930168 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930169
170/** @brief Get the attribute name handle from the attribute table entry
171 * @param[in] entry - Pointer to bios attribute table entry
172 * @return handle to identify the name of the attribute, this handle points
173 * to a string in the bios string table.
174 */
175uint16_t pldm_bios_table_attr_entry_decode_string_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930176 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930177
178/** @brief Find an entry in attribute table by handle
179 * @param[in] table - The BIOS Attribute Table
180 * @param[in] length - Length of the BIOS Attribute Table
181 * @param[in] handle - handle to identify the attribute in the attribute table
182 * @return Pointer to the entry
183 */
184const struct pldm_bios_attr_table_entry *
185pldm_bios_table_attr_find_by_handle(const void *table, size_t length,
186 uint16_t handle);
187
188/** @brief Find an entry in attribute table by string handle
189 * @param[in] table - The BIOS Attribute Table
190 * @param[in] length - Length of the BIOS Attribute Table
191 * @param[in] handle - The string handle
192 * @return Pointer to the entry
193 */
194const struct pldm_bios_attr_table_entry *
195pldm_bios_table_attr_find_by_string_handle(const void *table, size_t length,
196 uint16_t handle);
197
198/** @struct pldm_bios_table_attr_entry_enum_info
199 *
200 * An auxiliary structure for passing parameters to @ref
Andrew Jeffery6409c8a2023-06-14 11:38:31 +0930201 * pldm_bios_table_attr_entry_enum_encode_check
Andrew Jeffery9c766792022-08-10 23:12:49 +0930202 *
203 */
204struct pldm_bios_table_attr_entry_enum_info {
205 uint16_t name_handle; //!< attribute name handle
206 bool read_only; //!< indicate whether the attribute is read-only
207 uint8_t pv_num; //!< number of possible values
208 const uint16_t *pv_handle; //!< handles of possible values
209 uint8_t def_num; //!< nnumber of default values
210 const uint8_t *def_index; //!< indices of default values.
211};
212
213/** @brief Get length that an attribute entry(type: enum) will take
214 * @param[in] pv_num - Number of possible values
215 * @param[in] def_num - Number of default values
216 * @return The length that an entry(type: enum) will take
217 */
218size_t pldm_bios_table_attr_entry_enum_encode_length(uint8_t pv_num,
219 uint8_t def_num);
220
Andrew Jeffery9c766792022-08-10 23:12:49 +0930221/** @brief Create an entry of BIOS Attribute Table (type: enum) and check the
222 * validity of the parameters
223 * @param[out] entry - Pointer to a buffer to create an entry
224 * @param[in] entry_length - Length of the buffer to create an entry
225 * @param[in] info - Pointer to an auxiliary structure @ref
226 * pldm_bios_table_attr_entry_enum_info
Andrew Jeffery657bfd02023-06-14 07:14:42 +0930227 * @return PLDM_SUCCESS on success, otherwise PLDM_ERROR_INVALID_DATA if entry or info are NULL, or
228 * PLDM_ERROR_INVALID_LENGTH if entry_length is insufficient to encode info. An appropriate
229 * value for entry_length can be determined using @ref
230 * pldm_bios_table_attr_entry_enum_encode_length.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930231 */
232int pldm_bios_table_attr_entry_enum_encode_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930233 void *entry, size_t entry_length,
234 const struct pldm_bios_table_attr_entry_enum_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930235
Andrew Jeffery9c766792022-08-10 23:12:49 +0930236/** @brief Get the total number of possible values for the entry and check the
237 * validity of the parameters
238 * @param[in] entry - Pointer to bios attribute table entry
239 * @param[out] pv_num - Pointer to total number of possible values
Andrew Jeffery4f7ebda2023-06-13 21:49:38 +0930240 * @return PLDM_SUCCESS on success, PLDM_ERROR_INVALID_DATA if entry or pv_num are NULL, or
241 * PLDM_ERROR_INVALID_DATA if entry is not a valid PLDM_BIOS_ENUMERATION
Andrew Jeffery9c766792022-08-10 23:12:49 +0930242 */
243int pldm_bios_table_attr_entry_enum_decode_pv_num_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930244 const struct pldm_bios_attr_table_entry *entry, uint8_t *pv_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930245
Andrew Jeffery9c766792022-08-10 23:12:49 +0930246/** @brief Get the total number of default 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] def_num - Pointer to total number of default values
Andrew Jeffery437a83a2023-06-13 22:36:26 +0930250 * @return PLDM_SUCCESS on success, otherwise PLDM_ERROR_INVALID_DATA if entry or def_num are NULL,
251 * or entry is not of type PLDM_BIOS_ENUMERATION.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930252 */
253int pldm_bios_table_attr_entry_enum_decode_def_num_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930254 const struct pldm_bios_attr_table_entry *entry, uint8_t *def_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930255
Andrew Jeffery9c766792022-08-10 23:12:49 +0930256/** @brief Get possible values string handles and check the validity of the
257 * parameters
258 * @param[in] entry - Pointer to bios attribute table entry
Andrew Jeffery2ebec8d2023-06-13 22:16:08 +0930259 * @param[out] pv_hdls - Pointer to a buffer to store
Andrew Jeffery9c766792022-08-10 23:12:49 +0930260 * PossibleValuesStringHandles
261 * @param[in] pv_num - Number of PossibleValuesStringHandles the buffer can
Andrew Jeffery2ebec8d2023-06-13 22:16:08 +0930262 * store
Andrew Jefferyf3d851f2023-06-13 22:24:48 +0930263 * @return PLDM_SUCCESS on success, otherwise PLDM_ERROR_INVALID_DATA if entry or pv_hdls are NULL,
Andrew Jeffery0c9f5a82023-06-14 15:01:06 +0930264 * or entry is not of type PLDM_BIOS_ENUMERATION. An appropriate value for pv_num can be
265 * determined using @ref pldm_bios_table_attr_entry_enum_decode_pv_num_check. pv_num may be
266 * less than the value provided by @ref
267 * pldm_bios_table_attr_entry_enum_decode_pv_num_check, in which case only the first pv_num
268 * handles will be decoded.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930269 */
270int pldm_bios_table_attr_entry_enum_decode_pv_hdls_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930271 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
272 uint8_t pv_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930273
274/** @brief Get Indices of default values
275 * @param[in] entry - Pointer to bios attribute table entry
276 * @param[out] def_indices - Pointer to a buffer to store
277 * default value indices
278 * @param[in] def_num - Number of DefaultValues the buffer can
279 * store
280 * @return Number of default values decoded
281 */
282uint8_t pldm_bios_table_attr_entry_enum_decode_def_indices(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930283 const struct pldm_bios_attr_table_entry *entry, uint8_t *def_indices,
284 uint8_t def_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930285
286/** @struct pldm_bios_table_attr_entry_string_info
287 *
288 * An auxiliary structure for passing parameters to @ref
289 * pldm_bios_table_attr_entry_string_encode
290 *
291 */
292struct pldm_bios_table_attr_entry_string_info {
293 uint16_t name_handle; //!< attribute name handle
294 bool read_only; //!< indicate whether the attribute is read-only
295 uint8_t string_type; //!< The type of the string
296 uint16_t min_length; //!< The minimum length of the string in bytes
297 uint16_t max_length; //!< The maximum length of the string in bytes
298 uint16_t def_length; //!< The length of the defaut string in bytes
299 const char *def_string; //!< The default string itself
300};
301
302/** @brief Check fields in @ref pldm_bios_table_attr_entry_string_info
303 * @param[in] info - Pointer to the pldm_bios_table_attr_entry_string_info
304 * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
305 * memory
306 * @return pldm_completion_codes
307 */
308int pldm_bios_table_attr_entry_string_info_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930309 const struct pldm_bios_table_attr_entry_string_info *info,
310 const char **errmsg);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930311
312/** @brief Get length that an attribute entry(type: string) will take
313 * @param[in] def_str_len - Length of default string
314 * @return The length that an entry(type: string) will take
315 */
316size_t pldm_bios_table_attr_entry_string_encode_length(uint16_t def_str_len);
317
Andrew Jeffery9c766792022-08-10 23:12:49 +0930318/** @brief Create an entry of BIOS Attribute Table (type: string) and check the
319 * validity of the parameters
320 * @param[out] entry - Pointer to a buffer to create an entry
321 * @param[in] entry_length - Length of the buffer to create an entry
322 * @param[in] info - Pointer to an auxiliary structure @ref
323 * pldm_bios_table_attr_entry_string_info
Andrew Jefferya5c32872023-06-13 21:34:26 +0930324 * @return PLDM_SUCCESS on success, PLDM_ERROR_INVALID_DATA if entry or info are NULL or info
325 * contains logically inconsistent data, or PLDM_ERROR_INVALID_LENGTH if entry_length is
326 * not sufficient to encode info. An appropriate value for entry_length can be determined
327 * using @ref pldm_bios_table_attr_entry_string_encode_length
Andrew Jeffery9c766792022-08-10 23:12:49 +0930328 */
329int pldm_bios_table_attr_entry_string_encode_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930330 void *entry, size_t entry_length,
331 const struct pldm_bios_table_attr_entry_string_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930332
Andrew Jeffery9c766792022-08-10 23:12:49 +0930333/** @brief Get the length of default string in bytes for the entry and check the
334 * validity of the parameters
335 * @param[in] entry - Pointer to bios attribute table entry
336 * @param[out] def_string_length Pointer to length of default string in bytes
Andrew Jefferyb9a87692023-06-13 22:36:43 +0930337 * @return PLDM_SUCCESS on success, otherwise PLDM_ERROR_INVALID_DATA if entry or def_string_length
338 * are NULL, or entry is not of type PLDM_BIOS_STRING
Andrew Jeffery9c766792022-08-10 23:12:49 +0930339 */
340int pldm_bios_table_attr_entry_string_decode_def_string_length_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930341 const struct pldm_bios_attr_table_entry *entry,
342 uint16_t *def_string_length);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930343
344/** @brief Get the type of string of bios attribute table entry
345 * @param[in] entry - Pointer to bios attribute table entry
346 * @return Type of the string
347 */
348uint8_t pldm_bios_table_attr_entry_string_decode_string_type(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930349 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930350
351/** @brief Get maximum length of the string from a bios attribute table entry in
352 * bytes
353 * @param[in] entry - Pointer to a bios attribute table entry
354 * @return Maximum length of the string
355 */
356uint16_t pldm_bios_table_attr_entry_string_decode_max_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930357 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930358
359/** @brief Get minimum length of the string from a bios attribute table entry in
360 * bytes
361 * @param[in] entry - Pointer to a bios attribute table entry
362 * @return Minimum length of the string
363 */
364uint16_t pldm_bios_table_attr_entry_string_decode_min_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930365 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930366
367/** @brief Get the default string from a bios attribute table entry
368 * @param[out] buffer - Pointer to a buffer to store the string
369 * @param[in] size - Size of the buffer to store the string
370 * @return Length of the string decoded
371 */
372uint16_t pldm_bios_table_attr_entry_string_decode_def_string(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930373 const struct pldm_bios_attr_table_entry *entry, char *buffer,
374 size_t size);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930375
376/** @struct pldm_bios_table_attr_entry_integer_info
377 *
378 * An auxiliary structure for passing parameters to @ref
379 * pldm_bios_table_attr_entry_integer_encode
380 *
381 */
382struct pldm_bios_table_attr_entry_integer_info {
383 uint16_t name_handle; //!< attribute name handle
384 bool read_only; //!< indicate whether the attribute is read-only
385 uint64_t lower_bound; //!< The lower bound on the integer value
386 uint64_t upper_bound; //!< The upper bound on the integer value
387 uint32_t scalar_increment; //!< The scalar value that is used for the
388 //!< increments to this integer
389 uint64_t default_value; //!< The default value of the integer
390};
391
392/** @brief Check fields in @ref pldm_bios_table_attr_entry_integer_info
393 * @param[in] info - Pointer to the pldm_bios_table_attr_entry_integer_info
394 * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
395 * memory
396 * @return pldm_completion_codes
397 */
398int pldm_bios_table_attr_entry_integer_info_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930399 const struct pldm_bios_table_attr_entry_integer_info *info,
400 const char **errmsg);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930401
402/** @brief Get length that an attribute entry(type: integer) will take
403 * @return The length that an entry(type: integer) will take
404 */
Andrew Jeffery319304f2023-04-05 13:53:18 +0930405size_t pldm_bios_table_attr_entry_integer_encode_length(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930406
Andrew Jeffery9c766792022-08-10 23:12:49 +0930407/** @brief Create an entry of BIOS Attribute Table (type: integer) and check the
408 * validity of the parameters
409 * @param[out] entry - Pointer to a buffer to create an entry
410 * @param[in] entry_length - Length of the buffer to create an entry
411 * @param[in] info - Pointer to an auxiliary structure @ref
412 * pldm_bios_table_attr_entry_integer_info
Andrew Jefferyfe0f01d2023-06-27 11:51:58 +0930413 * @return PLDM_SUCCESS on success. PLDM_ERROR_INVALID_DATA if entry or info are null, or the data
414 * in info is not logically consistent. PLDM_ERROR_INVALID_LENGTH if entry_length lacks
415 * capacity to encode the attribute.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930416 */
417int pldm_bios_table_attr_entry_integer_encode_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930418 void *entry, size_t entry_length,
419 const struct pldm_bios_table_attr_entry_integer_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930420
421/** @brief Decode the specific fields(integer) of attribute table entry
422 * @param[in] entry - Pointer to an entry of attribute table
423 * @param[out] lower - The lower bound on the integer value
424 * @param[out] upper - The upper bound on the integer value
425 * @param[out] scalar - The scalar value that is used for the increments to
426 * this integer
427 * @param[out] def - The default value of the integer
428 */
429void pldm_bios_table_attr_entry_integer_decode(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930430 const struct pldm_bios_attr_table_entry *entry, uint64_t *lower,
431 uint64_t *upper, uint32_t *scalar, uint64_t *def);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930432
433/** @brief Get the attribute handle from the attribute value table entry
434 * @param[in] entry - Pointer to bios attribute value table entry
435 * @return handle to identify the attribute in the attribute value table
436 */
437uint16_t pldm_bios_table_attr_value_entry_decode_attribute_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930438 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930439
440/** @brief Get the attribute type from the attribute value table entry
441 * @param[in] entry - Pointer to bios attribute value table entry
442 * @return Type of the attribute value entry
443 */
444uint8_t pldm_bios_table_attr_value_entry_decode_attribute_type(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930445 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930446
447/** @brief Get length that an attribute value entry(type: enum) will take
448 * @param[in] count - Total number of current values for this enumeration
449 * @return The length that an entry(type: enum) will take
450 */
451size_t pldm_bios_table_attr_value_entry_encode_enum_length(uint8_t count);
452
Andrew Jeffery9c766792022-08-10 23:12:49 +0930453/** @brief Get number of current values for the enum entry
454 * @param[in] entry - Pointer to bios attribute value table entry
455 * @return Total number of current values for this enumeration
456 */
457uint8_t pldm_bios_table_attr_value_entry_enum_decode_number(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930458 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930459
460/** @brief Get CurrentValueStringHandleIndex
461 * @param[in] entry - Pointer to bios attribute value table entry
462 * @param[in, out] handles - Pointer to a buffer to store
463 * CurrentValueStringHandleIndex
464 * @param[in] number - Number of PossibleValuesStringHandles expected
465 * @return Number of CurrentValueStringHandleIndex decoded.
466 */
467uint8_t pldm_bios_table_attr_value_entry_enum_decode_handles(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930468 const struct pldm_bios_attr_val_table_entry *entry, uint8_t *handles,
469 uint8_t number);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930470
471/** @brief Create an attribute value entry(type: enum) and check the validity of
472 * the parameters
473 * @param[out] entry - Pointer to bios attribute value entry
474 * @param[in] entry_length - Length of attribute value entry
475 * @param[in] attr_handle - This handle points to an attribute in the
476 * BIOS Attribute Vlaue Table.
477 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
478 * Table
479 * @param[in] count - Total number of current values for this enum attribute
480 * @param[in] handle_indexes - Index into the array(provided in the BIOS
481 * Attribute Table) of the possible values of string handles for this attribute.
Andrew Jeffery7aeb7ed2023-06-27 13:13:36 +0930482 * @return PLDM_SUCCESS on success. PLDM_ERROR_INVALID_DATA if entry or handles are NULL, or if
483 * attr_type is not a PLDM_BIOS_ENUMERATION. PLDM_ERROR_INVALID_LENGTH if entry_length
484 * lacks capacity to encode handles into entry.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930485 */
486int pldm_bios_table_attr_value_entry_encode_enum_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930487 void *entry, size_t entry_length, uint16_t attr_handle,
Andrew Jeffery7aeb7ed2023-06-27 13:13:36 +0930488 uint8_t attr_type, uint8_t count, const uint8_t *handles);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930489
490/** @brief Get length that an attribute value entry(type: string) will take
491 * @param[in] string_length - Length of the current string in byte, 0 indicates
492 * that the current string value is not set.
493 * @return The length that an entry(type: string) will take
494 */
495size_t
496pldm_bios_table_attr_value_entry_encode_string_length(uint16_t string_length);
497
Andrew Jeffery9c766792022-08-10 23:12:49 +0930498/** @brief Get length of the current string in bytes
499 * @param [in] entry - Pointer to bios attribute value table entry
500 * @return The length of the current string in bytes
501 */
502uint16_t pldm_bios_table_attr_value_entry_string_decode_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930503 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930504
505/** @brief Get Current String Itself
506 * @param[in] entry - Pointer to bios attribute value table entry
507 * @param[in, out] current_string - Struct variable_field, contains a pointer
508 * to the CurrentString field in the buffer of
509 * \p entry, \p entry must be valid
510 * when \p current_string is used.
511 */
512void pldm_bios_table_attr_value_entry_string_decode_string(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930513 const struct pldm_bios_attr_val_table_entry *entry,
514 struct variable_field *current_string);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930515
516/** @brief Create an attribute value entry(type: string) and check the validity
517 * of the parameters
518 * @param[out] entry - Pointer to bios attribute value entry
519 * @param[in] entry_length - Length of attribute value entry
520 * @param[in] attr_handle - This handle points to an attribute in the
521 * BIOS Attribute Vlaue Table.
522 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
523 * Table
524 * @param[in] string_length - Length of current string in bytes. 0 indicates
525 * that the current string value is not set.
526 * @param[in] string - The current string itsel
Andrew Jeffery2d663932023-06-27 14:19:15 +0930527 * @return PLDM_SUCCESS on success. PLDM_ERROR_INVALID_DATA if entry is NULL, str is NULL while
528 * str_length is non-zero, or attr_type is not PLDM_BIOS_STRING. PLDM_ERROR_INVALID_LENGTH
529 * if entry_length lacks capacity to encode str into entry.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930530 */
531int pldm_bios_table_attr_value_entry_encode_string_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930532 void *entry, size_t entry_length, uint16_t attr_handle,
533 uint8_t attr_type, uint16_t str_length, const char *string);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930534
535/** @brief Get length that an attribute value entry(type: integer) will take
536 * @return The length that an entry(type: integer) will take
537 */
Andrew Jeffery319304f2023-04-05 13:53:18 +0930538size_t pldm_bios_table_attr_value_entry_encode_integer_length(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930539
Andrew Jeffery9c766792022-08-10 23:12:49 +0930540/** @brief Get current values for the integer entry
541 * @param[in] entry - Pointer to bios attribute value table entry
542 * @return Current Value
543 */
544uint64_t pldm_bios_table_attr_value_entry_integer_decode_cv(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930545 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930546
547/** @brief Create an attribute value entry(type: integer) and check the validity
548 * of the parameters
549 * @param[out] entry - Pointer to bios attribute value entry
550 * @param[in] entry_length - Length of attribute value entry
551 * @param[in] attr_handle - This handle points to an attribute in the
552 * BIOS Attribute Vlaue Table.
553 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
554 * Table
555 * @param[in] cv - Current Value
Andrew Jeffery0088a6a2023-06-27 15:06:45 +0930556 * @return PLDM_SUCCESS on success. PLDM_ERROR_INVALID_DATA if entry is NULL or attr_type is not
557 * PLDM_BIOS_INTEGER. PLDM_ERROR_INVALID_LENGTH if entry_length lacks capacity to encode cv
558 * in entry.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930559 */
560int pldm_bios_table_attr_value_entry_encode_integer_check(void *entry,
561 size_t entry_length,
562 uint16_t attr_handle,
563 uint8_t attr_type,
564 uint64_t cv);
565
566/** @brief Get the handle from the attribute value entry
567 * @param[in] entry - Pointer to bios attribute value entry
568 * @return handle to identify the attribute in the attribute value table
569 */
570uint16_t pldm_bios_table_attr_value_entry_decode_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930571 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930572
573/** @brief Get the length of the attribute value entry
574 * @param[in] entry - Pointer to bios attribute value entry
575 * @return Length of the entry
576 */
577size_t pldm_bios_table_attr_value_entry_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930578 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930579
580/** @brief Find an entry in attribute value table by handle
581 * @param[in] table - The BIOS Attribute Value Table
582 * @param[in] length - Length of the BIOS Attribute Value Table
583 * @param[in] handle - handle to identify the attribute in the attribute value
584 * table
585 * @return Pointer to the entry
586 */
587const struct pldm_bios_attr_val_table_entry *
588pldm_bios_table_attr_value_find_by_handle(const void *table, size_t length,
589 uint16_t handle);
590
591/** @brief Get the size of pad and checksum
592 * @param[in] size_without_pad - Table size without pad
593 * @return The size of pad and checksum
594 */
595size_t pldm_bios_table_pad_checksum_size(size_t size_without_pad);
596
Andrew Jeffery044ee192023-06-28 11:26:00 +0930597/** @brief Append pad and checksum at the end of the table or return an error
598 * @param[in,out] table - Pointer to a buffer of a bios table
599 * @param[in] capacity - Size of the buffer of a bios table
600 * @param[in,out] size - On input, the table size without pad and checksum, on output, the table
601 * with the padding and checksum appended
602 * @return PLDM_SUCCESS on success, PLDM_INVALID_DATA if table or size are NULL, or
603 * PLDM_ERROR_INVALID_LENGTH if size lacks capacity to encode the padded checksum in the
604 * buffer provided by table. The appropriate buffer capacity can be determined with the
605 * help of @ref pldm_bios_table_pad_checksum_size
606 */
607int pldm_bios_table_append_pad_checksum_check(void *table, size_t capacity,
608 size_t *size);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930609
610/** @brief Build a new table and update an entry
611 * @param[in] src_table - Pointer to the source table
612 * @param[in] src_length - Size of the source table
613 * @param[out] dest_table - Pointer to the buffer of destination table
614 * @param[in,out] dest_length - Buffer size of the destination table as input
615 * parameter and will be assigned the length of
616 * the new table, if the function returns
617 * PLDM_SUCCESS
618 * @param[in] entry - Pointer to an entry
619 * @param[in] entry_length - Size of the entry
620 * @return pldm_completion_codes
621 */
622int pldm_bios_table_attr_value_copy_and_update(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930623 const void *src_table, size_t src_length, void *dest_table,
624 size_t *dest_length, const void *entry, size_t entry_length);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930625
626/** @brief Verify the crc value of the complete table
627 * @param[in] table - Pointer to a buffer of a bios table
628 * @param[in] size - Size of the buffer of a bios table
629 * @return true: crc value is correct
630 */
631bool pldm_bios_table_checksum(const uint8_t *table, size_t size);
632
633#ifdef __cplusplus
634}
635#endif
636
637#endif