1 /* CSE FPT header version 0x20 */
2 /* SPDX-License-Identifier: GPL-2.0-only */
9 uint8_t marker
[4]; /* FPT_MARKER */
11 uint8_t hdr_version
; /* FPT_HDR_VERSION_20 */
12 uint8_t entry_version
; /* FPT_ENTRY_VERSION */
18 static bool match_version(struct buffer
*buff
)
20 const uint8_t *data
= buffer_get(buff
);
21 uint8_t version
= read_at_le8(data
, offsetof(struct fpt_hdr
, hdr_version
));
23 return version
== FPT_HDR_VERSION_20
;
26 static bool validate_fpt_hdr(const struct fpt_hdr
*h
)
28 if (memcmp(h
->marker
, FPT_MARKER
, sizeof(h
->marker
))) {
29 ERROR("Invalid FPT header marker!\n");
33 if (h
->hdr_version
!= FPT_HDR_VERSION_20
) {
34 ERROR("Invalid FPT header version(0x%x)!\n", h
->hdr_version
);
38 if (h
->entry_version
!= FPT_ENTRY_VERSION
) {
39 ERROR("Invalid FPT entry version(0x%x)!\n", h
->entry_version
);
43 const uint8_t *data
= (const uint8_t *)h
;
46 for (size_t i
= 0; i
< sizeof(*h
); i
++)
50 ERROR("Invalid checksum (0x%x)!\n", h
->hdr_checksum
);
57 static fpt_hdr_ptr
read_fpt_hdr(struct buffer
*buff
)
59 struct fpt_hdr
*h
= malloc(sizeof(*h
));
63 READ_MEMBER(buff
, h
->marker
);
64 READ_MEMBER(buff
, h
->num_entries
);
65 READ_MEMBER(buff
, h
->hdr_version
);
66 READ_MEMBER(buff
, h
->entry_version
);
67 READ_MEMBER(buff
, h
->hdr_length
);
68 READ_MEMBER(buff
, h
->hdr_checksum
);
69 READ_MEMBER(buff
, h
->rsvd
);
71 if (!validate_fpt_hdr(h
)) {
79 static void print_fpt_hdr(const fpt_hdr_ptr ptr
)
81 struct fpt_hdr
*h
= ptr
;
83 printf(" * FPT header\n");
84 printf("%-25s: %.4s\n", "Marker", h
->marker
);
85 printf("%-25s: %d\n", "Number of entries", h
->num_entries
);
86 printf("%-25s: 0x%x\n", "Header version", h
->hdr_version
);
87 printf("%-25s: 0x%x\n", "Entry version", h
->entry_version
);
88 printf("%-25s: %d\n", "Header length", h
->hdr_length
);
89 printf("%-25s: 0x%x\n", "Header checksum", h
->hdr_checksum
);
92 static size_t get_entry_count(const fpt_hdr_ptr ptr
)
94 struct fpt_hdr
*h
= ptr
;
96 return h
->num_entries
;
99 const struct fpt_hdr_ops fpt_hdr_20_ops
= {
100 .match_version
= match_version
,
102 .read
= read_fpt_hdr
,
103 .print
= print_fpt_hdr
,
105 .get_entry_count
= get_entry_count
,