aboutsummaryrefslogtreecommitdiff
path: root/pldm/include/libpldm/bios_table.h
blob: 76f41d171a31716a16ccce5a85273a10b0c3d87f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
#ifndef LIBPLDM_BIOS_TABLE_H
#define LIBPLDM_BIOS_TABLE_H

#ifdef __cplusplus
extern "C" {
#endif

#include "bios.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
struct variable_field;

/** @struct pldm_bios_table_iter
 *  structure representing bios table iterator
 */
struct pldm_bios_table_iter;

/** @brief Create a bios table iterator
 *  @param[in] table - Pointer to table data
 *  @param[in] length - Length of table data
 *  @param[in] type - Type of pldm bios table
 *  @return Iterator to the beginning
 */
struct pldm_bios_table_iter *
pldm_bios_table_iter_create(const void *table, size_t length,
			    enum pldm_bios_table_types type);

/** @brief Release a bios table iterator
 *  @param[in] iter - Pointer to bios table iterator
 */
void pldm_bios_table_iter_free(struct pldm_bios_table_iter *iter);

/** @brief Check if the iterator reaches the end of the bios table
 *  @param[in] iter - Pointer to the bios table iterator
 *  @return true if iterator reaches the end
 *  @note *end* is a position after the last entry.
 */
bool pldm_bios_table_iter_is_end(const struct pldm_bios_table_iter *iter);

/** @brief Get iterator to next entry
 *  @param[in] iter - Pointer the bios table iterator
 */
void pldm_bios_table_iter_next(struct pldm_bios_table_iter *iter);

/** @brief Get the bios table entry that the iterator points to
 *  @param[in] iter - Pointer to the bios table iterator
 *  @return Pointer to an entry in bios table
 */
const void *pldm_bios_table_iter_value(struct pldm_bios_table_iter *iter);

/** @brief Get the bios attribute table entry that the iterator points to
 *  @param[in] iter - Pointer the bios attribute table iterator
 *  @return Pointer to an entry in bios attribute table
 */
static inline const struct pldm_bios_attr_table_entry *
pldm_bios_table_iter_attr_entry_value(struct pldm_bios_table_iter *iter)
{
	return (const struct pldm_bios_attr_table_entry *)
		pldm_bios_table_iter_value(iter);
}

/** @brief Get the bios string table entry that the iterator ponit to
 *  @param[in] iter - Pointer the bios string table iterator
 *  @return Pointer to an entry in bios string table
 */
static inline const struct pldm_bios_string_table_entry *
pldm_bios_table_iter_string_entry_value(struct pldm_bios_table_iter *iter)
{
	return (const struct pldm_bios_string_table_entry *)
		pldm_bios_table_iter_value(iter);
}

/** @brief Get the bios attribute value table entry that the iterator ponit to
 *  @param[in] iter - Pointer the bios attribute value table iterator
 *  @return Pointer to an entry in bios attribute value table
 */
static inline const struct pldm_bios_attr_val_table_entry *
pldm_bios_table_iter_attr_value_entry_value(struct pldm_bios_table_iter *iter)
{
	return (const struct pldm_bios_attr_val_table_entry *)
		pldm_bios_table_iter_value(iter);
}

/** @brief Get the length of an entry in the BIOS String Table
 *  @param[in] string_length - Length of string
 *  @return Length of an entry in bytes
 */
size_t pldm_bios_table_string_entry_encode_length(uint16_t string_length);

/** @brief Create an entry of BIOS String Table
 *  @param[out] entry - Pointer to a buffer to create an entry
 *  @param[in] entry_length - Length of the buffer to create an entry
 *  @param[in] str - String itself
 *  @param[in] str_length - Length of the string
 */
void pldm_bios_table_string_entry_encode(void *entry, size_t entry_length,
					 const char *str, uint16_t str_length);

/** @brief Create an entry of BIOS String Table and check the validity of the
 * parameters
 *  @param[out] entry - Pointer to a buffer to create an entry
 *  @param[in] entry_length - Length of the buffer to create an entry
 *  @param[in] str - String itself
 *  @param[in] str_length - Length of the string
 *  @return pldm_completion_codes
 */
int pldm_bios_table_string_entry_encode_check(void *entry, size_t entry_length,
					      const char *str,
					      uint16_t str_length);

/** @brief Get the string handle for the entry
 *  @param[in] entry - Pointer to a bios string table entry
 *  @return Handle to identify a string in the bios string table
 */
uint16_t pldm_bios_table_string_entry_decode_handle(
	const struct pldm_bios_string_table_entry *entry);

/** @brief Get the string length for the entry
 *  @param[in] entry - Pointer to a bios string table entry
 *  @return Length of string in bytes
 */
uint16_t pldm_bios_table_string_entry_decode_string_length(
	const struct pldm_bios_string_table_entry *entry);

/** @brief Get the string(at most one less than *size* characters) from the
 * entry
 *  @param[in] entry - Pointer to a bios string table entry
 *  @param[out] buffer - Pointer to a buffer to store the string
 *  @param[in] size - Size of the buffer to store the string
 *  @return Length of the string decoded
 */
uint16_t pldm_bios_table_string_entry_decode_string(
	const struct pldm_bios_string_table_entry *entry, char *buffer,
	size_t size);

/** @brief Get the string from the entry and check the validity of the
 * parameters
 *  @param[in] entry - Pointer to a bios string table entry
 *  @param[out] buffer - Pointer to a buffer to store the string
 *  @param[in] size - Size of the buffer to store the string
 *  @return pldm_completion_codes
 */
int pldm_bios_table_string_entry_decode_string_check(
	const struct pldm_bios_string_table_entry *entry, char *buffer,
	size_t size);

/** @brief Find an entry in bios string table by string
 *  @param[in] table - The BIOS String Table
 *  @param[in] length - Length of the BIOS String Table
 *  @param[in] str - String itself
 *  @return Pointer to an entry in the bios string table
 */
const struct pldm_bios_string_table_entry *
pldm_bios_table_string_find_by_string(const void *table, size_t length,
				      const char *str);
/** @brief Find an entry in bios string table by handle
 *  @param[in] table - The BIOS String Table
 *  @param[in] length - Length of the BIOS String Table
 *  @param[in] handle - Handle to identify a string in the bios string table
 *  @return Pointer to an entry in the bios string table
 */
const struct pldm_bios_string_table_entry *
pldm_bios_table_string_find_by_handle(const void *table, size_t length,
				      uint16_t handle);

/** @brief Get the attribute handle from the attribute table entry
 *  @param[in] entry - Pointer to bios attribute table entry
 *  @return handle to identify the attribute in the attribute table
 */
uint16_t pldm_bios_table_attr_entry_decode_attribute_handle(
	const struct pldm_bios_attr_table_entry *entry);

/** @brief Get the attribute type of the attribute table entry
 *  @param[in] entry - Pointer to bios attribute table entry
 *  @return Type of the attribute table entry
 */
uint8_t pldm_bios_table_attr_entry_decode_attribute_type(
	const struct pldm_bios_attr_table_entry *entry);

/** @brief Get the attribute name handle from the attribute table entry
 *  @param[in] entry - Pointer to bios attribute table entry
 *  @return handle to identify the name of the attribute, this handle points
 *          to a string in the bios string table.
 */
uint16_t pldm_bios_table_attr_entry_decode_string_handle(
	const struct pldm_bios_attr_table_entry *entry);

/** @brief Find an entry in attribute table by handle
 *  @param[in] table - The BIOS Attribute Table
 *  @param[in] length - Length of the BIOS Attribute Table
 *  @param[in] handle - handle to identify the attribute in the attribute table
 *  @return Pointer to the entry
 */
const struct pldm_bios_attr_table_entry *
pldm_bios_table_attr_find_by_handle(const void *table, size_t length,
				    uint16_t handle);

/** @brief Find an entry in attribute table by string handle
 *  @param[in] table - The BIOS Attribute Table
 *  @param[in] length - Length of the BIOS Attribute Table
 *  @param[in] handle - The string handle
 *  @return Pointer to the entry
 */
const struct pldm_bios_attr_table_entry *
pldm_bios_table_attr_find_by_string_handle(const void *table, size_t length,
					   uint16_t handle);

/** @struct pldm_bios_table_attr_entry_enum_info
 *
 *  An auxiliary structure for passing parameters to @ref
 * pldm_bios_table_attr_entry_enum_encode
 *
 */
struct pldm_bios_table_attr_entry_enum_info {
	uint16_t name_handle; //!< attribute name handle
	bool read_only;	      //!< indicate whether the attribute is read-only
	uint8_t pv_num;	      //!< number of possible values
	const uint16_t *pv_handle; //!< handles of possible values
	uint8_t def_num;	   //!< nnumber of default values
	const uint8_t *def_index;  //!< indices of default values.
};

/** @brief Get length that an attribute entry(type: enum) will take
 *  @param[in] pv_num - Number of possible values
 *  @param[in] def_num - Number of default values
 *  @return The length that an entry(type: enum) will take
 */
size_t pldm_bios_table_attr_entry_enum_encode_length(uint8_t pv_num,
						     uint8_t def_num);

/** @brief Create an entry of BIOS Attribute Table (type: enum)
 *  @param[out] entry - Pointer to a buffer to create an entry
 *  @param[in] entry_length - Length of the buffer to create an entry
 *  @param[in] info - Pointer to an auxiliary structure @ref
 * pldm_bios_table_attr_entry_enum_info
 */
void pldm_bios_table_attr_entry_enum_encode(
	void *entry, size_t entry_length,
	const struct pldm_bios_table_attr_entry_enum_info *info);

/** @brief Create an entry of BIOS Attribute Table (type: enum) and check the
 * validity of the parameters
 *  @param[out] entry - Pointer to a buffer to create an entry
 *  @param[in] entry_length - Length of the buffer to create an entry
 *  @param[in] info - Pointer to an auxiliary structure @ref
 * pldm_bios_table_attr_entry_enum_info
 *  @return pldm_completion_codes
 */
int pldm_bios_table_attr_entry_enum_encode_check(
	void *entry, size_t entry_length,
	const struct pldm_bios_table_attr_entry_enum_info *info);

/** @brief Get the total number of possible values for the entry
 *  @param[in] entry - Pointer to bios attribute table entry
 *  @return total number of possible values
 */
uint8_t pldm_bios_table_attr_entry_enum_decode_pv_num(
	const struct pldm_bios_attr_table_entry *entry);

/** @brief Get the total number of possible values for the entry and check the
 * validity of the parameters
 *  @param[in] entry - Pointer to bios attribute table entry
 *  @param[out] pv_num - Pointer to total number of possible values
 *  @return pldm_completion_codes
 */
int pldm_bios_table_attr_entry_enum_decode_pv_num_check(
	const struct pldm_bios_attr_table_entry *entry, uint8_t *pv_num);

/** @brief Get the total number of default values for the entry
 *  @param[in] entry - Pointer to bios attribute table entry
 *  @return total number of default values
 */
uint8_t pldm_bios_table_attr_entry_enum_decode_def_num(
	const struct pldm_bios_attr_table_entry *entry);

/** @brief Get the total number of default values for the entry and check the
 * validity of the parameters
 *  @param[in] entry - Pointer to bios attribute table entry
 *  @param[out] def_num - Pointer to total number of default values
 *  @return pldm_completion_codes
 */
int pldm_bios_table_attr_entry_enum_decode_def_num_check(
	const struct pldm_bios_attr_table_entry *entry, uint8_t *def_num);

/** @brief Get possible values string handles
 *  @param[in] entry - Pointer to bios attribute table entry
 *  @param[out] pv_hdls - Pointer to a buffer to stroe
 * PossibleValuesStringHandles
 *  @param[in] pv_num - Number of PossibleValuesStringHandles expected
 *  @return pldm_completion_codes
 */
uint8_t pldm_bios_table_attr_entry_enum_decode_pv_hdls(
	const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
	uint8_t pv_num);

/** @brief Get possible values string handles and check the validity of the
 * parameters
 *  @param[in] entry - Pointer to bios attribute table entry
 *  @param[out] pv_hdls - Pointer to a buffer to stroe
 * PossibleValuesStringHandles
 *  @param[in] pv_num - Number of PossibleValuesStringHandles the buffer can
 * stroe
 *  @return Number of PossibleValuesStringHandles decoded
 */
int pldm_bios_table_attr_entry_enum_decode_pv_hdls_check(
	const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
	uint8_t pv_num);

/** @brief Get Indices of default values
 *  @param[in] entry - Pointer to bios attribute table entry
 *  @param[out] def_indices - Pointer to a buffer to store
 *                            default value indices
 *  @param[in] def_num - Number of DefaultValues the buffer can
 *                       store
 *  @return Number of default values decoded
 */
uint8_t pldm_bios_table_attr_entry_enum_decode_def_indices(
	const struct pldm_bios_attr_table_entry *entry, uint8_t *def_indices,
	uint8_t def_num);

/** @struct pldm_bios_table_attr_entry_string_info
 *
 *  An auxiliary structure for passing parameters to @ref
 * pldm_bios_table_attr_entry_string_encode
 *
 */
struct pldm_bios_table_attr_entry_string_info {
	uint16_t name_handle;	//!< attribute name handle
	bool read_only;		//!< indicate whether the attribute is read-only
	uint8_t string_type;	//!< The type of the string
	uint16_t min_length;	//!< The minimum length of the string in bytes
	uint16_t max_length;	//!< The maximum length of the string in bytes
	uint16_t def_length;	//!< The length of the defaut string in bytes
	const char *def_string; //!< The default string itself
};

/** @brief Check fields in @ref pldm_bios_table_attr_entry_string_info
 *  @param[in] info - Pointer to the pldm_bios_table_attr_entry_string_info
 *  @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
 * memory
 *  @return pldm_completion_codes
 */
int pldm_bios_table_attr_entry_string_info_check(
	const struct pldm_bios_table_attr_entry_string_info *info,
	const char **errmsg);

/** @brief Get length that an attribute entry(type: string) will take
 *  @param[in] def_str_len - Length of default string
 *  @return The length that an entry(type: string) will take
 */
size_t pldm_bios_table_attr_entry_string_encode_length(uint16_t def_str_len);

/** @brief Create an entry of BIOS Attribute Table (type: string)
 *  @param[out] entry - Pointer to a buffer to create an entry
 *  @param[in] entry_length - Length of the buffer to create an entry
 *  @param[in] info - Pointer to an auxiliary structure @ref
 * pldm_bios_table_attr_entry_string_info
 */
void pldm_bios_table_attr_entry_string_encode(
	void *entry, size_t entry_length,
	const struct pldm_bios_table_attr_entry_string_info *info);

/** @brief Create an entry of BIOS Attribute Table (type: string) and check the
 * validity of the parameters
 *  @param[out] entry - Pointer to a buffer to create an entry
 *  @param[in] entry_length - Length of the buffer to create an entry
 *  @param[in] info - Pointer to an auxiliary structure @ref
 * pldm_bios_table_attr_entry_string_info
 *  @return pldm_completion_codes
 */
int pldm_bios_table_attr_entry_string_encode_check(
	void *entry, size_t entry_length,
	const struct pldm_bios_table_attr_entry_string_info *info);

/** @brief Get the length of default string in bytes for the entry
 *  @param[in] entry - Pointer to bios attribute table entry
 *  @return length of default string in bytes
 */
uint16_t pldm_bios_table_attr_entry_string_decode_def_string_length(
	const struct pldm_bios_attr_table_entry *entry);

/** @brief Get the length of default string in bytes for the entry and check the
 * validity of the parameters
 *  @param[in] entry - Pointer to bios attribute table entry
 *  @param[out] def_string_length Pointer to length of default string in bytes
 *  @return pldm_completion_codes
 */
int pldm_bios_table_attr_entry_string_decode_def_string_length_check(
	const struct pldm_bios_attr_table_entry *entry,
	uint16_t *def_string_length);

/** @brief Get the type of string of bios attribute table entry
 *  @param[in] entry - Pointer to bios attribute table entry
 *  @return Type of the string
 */
uint8_t pldm_bios_table_attr_entry_string_decode_string_type(
	const struct pldm_bios_attr_table_entry *entry);

/** @brief Get maximum length of the string from a bios attribute table entry in
 * bytes
 *  @param[in] entry - Pointer to a bios attribute table entry
 *  @return Maximum length of the string
 */
uint16_t pldm_bios_table_attr_entry_string_decode_max_length(
	const struct pldm_bios_attr_table_entry *entry);

/** @brief Get minimum length of the string from a bios attribute table entry in
 * bytes
 *  @param[in] entry - Pointer to a bios attribute table entry
 *  @return Minimum length of the string
 */
uint16_t pldm_bios_table_attr_entry_string_decode_min_length(
	const struct pldm_bios_attr_table_entry *entry);

/** @brief Get the default string from a bios attribute table entry
 *  @param[out] buffer - Pointer to a buffer to store the string
 *  @param[in] size - Size of the buffer to store the string
 *  @return Length of the string decoded
 */
uint16_t pldm_bios_table_attr_entry_string_decode_def_string(
	const struct pldm_bios_attr_table_entry *entry, char *buffer,
	size_t size);

/** @struct pldm_bios_table_attr_entry_integer_info
 *
 *  An auxiliary structure for passing parameters to @ref
 * pldm_bios_table_attr_entry_integer_encode
 *
 */
struct pldm_bios_table_attr_entry_integer_info {
	uint16_t name_handle; //!< attribute name handle
	bool read_only;	      //!< indicate whether the attribute is read-only
	uint64_t lower_bound; //!< The lower bound on the integer value
	uint64_t upper_bound; //!< The upper bound on the integer value
	uint32_t scalar_increment; //!< The scalar value that is used for the
				   //!< increments to this integer
	uint64_t default_value;	   //!< The default value of the integer
};

/** @brief Check fields in @ref pldm_bios_table_attr_entry_integer_info
 *  @param[in] info - Pointer to the pldm_bios_table_attr_entry_integer_info
 *  @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
 * memory
 *  @return pldm_completion_codes
 */
int pldm_bios_table_attr_entry_integer_info_check(
	const struct pldm_bios_table_attr_entry_integer_info *info,
	const char **errmsg);

/** @brief Get length that an attribute entry(type: integer) will take
 *  @return The length that an entry(type: integer) will take
 */
size_t pldm_bios_table_attr_entry_integer_encode_length(void);

/** @brief Create an entry of BIOS Attribute Table (type: integer)
 *  @param[out] entry - Pointer to a buffer to create an entry
 *  @param[in] entry_length - Length of the buffer to create an entry
 *  @param[in] info - Pointer to an auxiliary structure @ref
 * pldm_bios_table_attr_entry_integer_info
 */
void pldm_bios_table_attr_entry_integer_encode(
	void *entry, size_t entry_length,
	const struct pldm_bios_table_attr_entry_integer_info *info);

/** @brief Create an entry of BIOS Attribute Table (type: integer) and check the
 * validity of the parameters
 *  @param[out] entry - Pointer to a buffer to create an entry
 *  @param[in] entry_length - Length of the buffer to create an entry
 *  @param[in] info - Pointer to an auxiliary structure @ref
 * pldm_bios_table_attr_entry_integer_info
 *  @return pldm_completion_codes
 */
int pldm_bios_table_attr_entry_integer_encode_check(
	void *entry, size_t entry_length,
	const struct pldm_bios_table_attr_entry_integer_info *info);

/** @brief Decode the specific fields(integer) of attribute table entry
 *  @param[in] entry - Pointer to an entry of attribute table
 *  @param[out] lower - The lower bound on the integer value
 *  @param[out] upper - The upper bound on the integer value
 *  @param[out] scalar - The scalar value that is used for the increments to
 *                       this integer
 *  @param[out] def - The default value of the integer
 */
void pldm_bios_table_attr_entry_integer_decode(
	const struct pldm_bios_attr_table_entry *entry, uint64_t *lower,
	uint64_t *upper, uint32_t *scalar, uint64_t *def);

/** @brief Get the attribute handle from the attribute value table entry
 *  @param[in] entry - Pointer to bios attribute value table entry
 *  @return handle to identify the attribute in the attribute value table
 */
uint16_t pldm_bios_table_attr_value_entry_decode_attribute_handle(
	const struct pldm_bios_attr_val_table_entry *entry);

/** @brief Get the attribute type from the attribute value table entry
 *  @param[in] entry - Pointer to bios attribute value table entry
 *  @return Type of the attribute value entry
 */
uint8_t pldm_bios_table_attr_value_entry_decode_attribute_type(
	const struct pldm_bios_attr_val_table_entry *entry);

/** @brief Get length that an attribute value entry(type: enum) will take
 *  @param[in] count - Total number of current values for this enumeration
 *  @return The length that an entry(type: enum) will take
 */
size_t pldm_bios_table_attr_value_entry_encode_enum_length(uint8_t count);

/** @brief Create an attribute value entry(type: enum)
 *  @param[out] entry - Pointer to bios attribute value entry
 *  @param[in] entry_length - Length of attribute value entry
 *  @param[in] attr_handle - This handle points to an attribute in the
 *  BIOS Attribute Vlaue Table.
 *  @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
 * Table
 *  @param[in] count - Total number of current values for this enum attribute
 *  @param[in] handle_indexes - Index into the array(provided in the BIOS
 * Attribute Table) of the possible values of string handles for this attribute.
 */
void pldm_bios_table_attr_value_entry_encode_enum(
	void *entry, size_t entry_length, uint16_t attr_handle,
	uint8_t attr_type, uint8_t count, const uint8_t *handles);

/** @brief Get number of current values for the enum entry
 *  @param[in] entry - Pointer to bios attribute value table entry
 *  @return Total number of current values for this enumeration
 */
uint8_t pldm_bios_table_attr_value_entry_enum_decode_number(
	const struct pldm_bios_attr_val_table_entry *entry);

/** @brief Get CurrentValueStringHandleIndex
 *  @param[in] entry - Pointer to bios attribute value table entry
 *  @param[in, out] handles - Pointer to a buffer to store
 *                            CurrentValueStringHandleIndex
 *  @param[in] number - Number of PossibleValuesStringHandles expected
 *  @return Number of CurrentValueStringHandleIndex decoded.
 */
uint8_t pldm_bios_table_attr_value_entry_enum_decode_handles(
	const struct pldm_bios_attr_val_table_entry *entry, uint8_t *handles,
	uint8_t number);

/** @brief Create an attribute value entry(type: enum) and check the validity of
 * the parameters
 *  @param[out] entry - Pointer to bios attribute value entry
 *  @param[in] entry_length - Length of attribute value entry
 *  @param[in] attr_handle - This handle points to an attribute in the
 *  BIOS Attribute Vlaue Table.
 *  @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
 * Table
 *  @param[in] count - Total number of current values for this enum attribute
 *  @param[in] handle_indexes - Index into the array(provided in the BIOS
 * Attribute Table) of the possible values of string handles for this attribute.
 *  @return pldm_completion_codes
 */
int pldm_bios_table_attr_value_entry_encode_enum_check(
	void *entry, size_t entry_length, uint16_t attr_handle,
	uint8_t attr_type, uint8_t count, uint8_t *handles);

/** @brief Get length that an attribute value entry(type: string) will take
 *  @param[in] string_length - Length of the current string in byte, 0 indicates
 *  that the current string value is not set.
 *  @return The length that an entry(type: string) will take
 */
size_t
pldm_bios_table_attr_value_entry_encode_string_length(uint16_t string_length);

/** @brief Create an attribute value entry(type: string)
 *  @param[out] entry - Pointer to bios attribute value entry
 *  @param[in] entry_length - Length of attribute value entry
 *  @param[in] attr_handle - This handle points to an attribute in the
 *  BIOS Attribute Vlaue Table.
 *  @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
 * Table
 *  @param[in] string_length - Length of current string in bytes. 0 indicates
 * that the current string value is not set.
 *  @param[in] string - The current string itsel
 */
void pldm_bios_table_attr_value_entry_encode_string(
	void *entry, size_t entry_length, uint16_t attr_handle,
	uint8_t attr_type, uint16_t str_length, const char *string);

/** @brief Get length of the current string in bytes
 *  @param [in] entry - Pointer to bios attribute value table entry
 *  @return The length of the current string in bytes
 */
uint16_t pldm_bios_table_attr_value_entry_string_decode_length(
	const struct pldm_bios_attr_val_table_entry *entry);

/** @brief Get Current String Itself
 *  @param[in] entry - Pointer to bios attribute value table entry
 *  @param[in, out] current_string - Struct variable_field, contains a pointer
 *                                   to the CurrentString field in the buffer of
 *                                    \p entry, \p entry must be valid
 *                                    when \p current_string is used.
 */
void pldm_bios_table_attr_value_entry_string_decode_string(
	const struct pldm_bios_attr_val_table_entry *entry,
	struct variable_field *current_string);

/** @brief Create an attribute value entry(type: string) and check the validity
 * of the parameters
 *  @param[out] entry - Pointer to bios attribute value entry
 *  @param[in] entry_length - Length of attribute value entry
 *  @param[in] attr_handle - This handle points to an attribute in the
 *  BIOS Attribute Vlaue Table.
 *  @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
 * Table
 *  @param[in] string_length - Length of current string in bytes. 0 indicates
 * that the current string value is not set.
 *  @param[in] string - The current string itsel
 *  @return pldm_completion_codes
 */
int pldm_bios_table_attr_value_entry_encode_string_check(
	void *entry, size_t entry_length, uint16_t attr_handle,
	uint8_t attr_type, uint16_t str_length, const char *string);

/** @brief Get length that an attribute value entry(type: integer) will take
 *  @return The length that an entry(type: integer) will take
 */
size_t pldm_bios_table_attr_value_entry_encode_integer_length(void);

/** @brief Create an attribute value entry(type: integer)
 *  @param[out] entry - Pointer to bios attribute value entry
 *  @param[in] entry_length - Length of attribute value entry
 *  @param[in] attr_handle - This handle points to an attribute in the
 *  BIOS Attribute Vlaue Table.
 *  @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
 * Table
 *  @param[in] cv - Current Value
 */
void pldm_bios_table_attr_value_entry_encode_integer(void *entry,
						     size_t entry_length,
						     uint16_t attr_handle,
						     uint8_t attr_type,
						     uint64_t cv);

/** @brief Get current values for the integer entry
 *  @param[in] entry - Pointer to bios attribute value table entry
 *  @return Current Value
 */
uint64_t pldm_bios_table_attr_value_entry_integer_decode_cv(
	const struct pldm_bios_attr_val_table_entry *entry);

/** @brief Create an attribute value entry(type: integer) and check the validity
 * of the parameters
 *  @param[out] entry - Pointer to bios attribute value entry
 *  @param[in] entry_length - Length of attribute value entry
 *  @param[in] attr_handle - This handle points to an attribute in the
 *  BIOS Attribute Vlaue Table.
 *  @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
 * Table
 *  @param[in] cv - Current Value
 *  @return pldm_completion_codes
 */
int pldm_bios_table_attr_value_entry_encode_integer_check(void *entry,
							  size_t entry_length,
							  uint16_t attr_handle,
							  uint8_t attr_type,
							  uint64_t cv);

/** @brief Get the handle from the attribute value entry
 *  @param[in] entry - Pointer to bios attribute value entry
 *  @return handle to identify the attribute in the attribute value table
 */
uint16_t pldm_bios_table_attr_value_entry_decode_handle(
	const struct pldm_bios_attr_val_table_entry *entry);

/** @brief Get the length of the attribute value entry
 *  @param[in] entry - Pointer to bios attribute value entry
 *  @return Length of the entry
 */
size_t pldm_bios_table_attr_value_entry_length(
	const struct pldm_bios_attr_val_table_entry *entry);

/** @brief Find an entry in attribute value table by handle
 *  @param[in] table - The BIOS Attribute Value Table
 *  @param[in] length - Length of the BIOS Attribute Value Table
 *  @param[in] handle - handle to identify the attribute in the attribute value
 * table
 *  @return Pointer to the entry
 */
const struct pldm_bios_attr_val_table_entry *
pldm_bios_table_attr_value_find_by_handle(const void *table, size_t length,
					  uint16_t handle);

/** @brief Get the size of pad and checksum
 *  @param[in] size_without_pad - Table size without pad
 *  @return The size of pad and checksum
 */
size_t pldm_bios_table_pad_checksum_size(size_t size_without_pad);

/** @brief Append pad and checksum at the end of the table
 *  @param[in,out] table - Pointer to a buffer of a bios table
 *  @param[in] size - Size of the buffer of a bios table
 *  @param[in] size_without_pad - Table size without pad and checksum
 *  @return Total size of the table
 */
size_t pldm_bios_table_append_pad_checksum(void *table, size_t size,
					   size_t size_without_pad);

/** @brief Build a new table and update an entry
 *  @param[in] src_table - Pointer to the source table
 *  @param[in] src_length - Size of the source table
 *  @param[out] dest_table - Pointer to the buffer of destination table
 *  @param[in,out] dest_length - Buffer size of the destination table as input
 *                               parameter and will be assigned the length of
 *                               the new table, if the function returns
 * 				 PLDM_SUCCESS
 *  @param[in] entry - Pointer to an entry
 *  @param[in] entry_length - Size of the entry
 *  @return pldm_completion_codes
 */
int pldm_bios_table_attr_value_copy_and_update(
	const void *src_table, size_t src_length, void *dest_table,
	size_t *dest_length, const void *entry, size_t entry_length);

/** @brief Verify the crc value of the complete table
 *  @param[in] table - Pointer to a buffer of a bios table
 *  @param[in] size - Size of the buffer of a bios table
 *  @return true: crc value is correct
 */
bool pldm_bios_table_checksum(const uint8_t *table, size_t size);

#ifdef __cplusplus
}
#endif

#endif