// SPDX-License-Identifier: MPL-2.0
#ifndef BP_LIB_VFTM_H
#define BP_LIB_VFTM_H
#include <Uefi.h>
#include <Protocol/BlockIo.h>
#include "common/versions.h"
#define BP_VFTM_SIGNATURE {'V','y','F','a','t','S','i','g'}
#define BP_VFTM_SUPPORTED_MANIFEST_VERSION VY_COMMON_VERSIONS_MANIFEST
#define BP_VFTM_SUPPORTED_OS_VERSION VY_COMMON_VERSIONS_OS
#define BP_VFTM_SUPPORTED_BOOTLOADER_VERSION VY_COMMON_VERSIONS_BOOTLOADER
#pragma pack(1)
typedef struct {
  UINT8 sig[8];
  UINT16 manifest_version;
  UINT16 bootloader_version;
  UINT32 os_version;
  UINT8 fat_hash[64];
  UINT8 fat_build_id[32];
  UINT64 clusters_count;
  UINT64 bytes_per_sector;
  UINT64 sectors_per_cluster;
  UINT64 fat_size_bytes;
  UINT64 fat_offset_bytes;
  UINT64 bootloader_cluster_count;
  UINT64 bootloader_cluster_offset;
  UINT64 bootloader_build_id;
  UINT8 fat_header_hash[64];
  UINT8 bootloader_binary_hash[64];
  UINT64 signature_offset_bytes;
  UINT64 signature_size;
  UINT8 gpt_disk_guid[16];
  UINT8 gpt_efi_part_unique_guid[16];
  UINT8 manifest_hash[64];
} bp_vftm_MANIFEST;
#pragma pack()
typedef struct {
  UINT8 disk_guid[16];
  UINT8 efi_part_unique_guid[16];
  bp_vftm_MANIFEST manifest;
  UINT8 pk_manifest[64];
  UINT8 *manifest_signature;
  EFI_BLOCK_IO_PROTOCOL *block_io_esp;
  EFI_BLOCK_IO_PROTOCOL *block_io_disk;
  UINT8 *partition_table_buffer;
  UINTN part_count;
} bp_vftm_VFTM_ASSETS;
#pragma pack(1)
typedef struct {
  UINT8 BS_JmpBoot[3];
  UINT8 BS_OEMName[8];
  UINT16 BPB_BytsPerSec;
  UINT8 BPB_SecPerClus;
  UINT16 BPB_RsvdSecCnt;
  UINT8 BPB_NumFATs;
  UINT16 BPB_RootEntCnt;
  UINT16 BPB_TotSec16;
  UINT8 BPB_Media;
  UINT16 BPB_FATSz16;
  UINT16 BPB_SecPerTrk;
  UINT16 BPB_NumHeads;
  UINT32 BPB_HiddSec;
  UINT32 BPB_TotSec32;
  UINT32 BPB_FATSz32;
  UINT16 BPB_ExtFlags;
  UINT16 BPB_FSVer;
  UINT32 BPB_RootClus;
  UINT16 BPB_FSInfo;
  UINT16 BPB_BkBootSec;
  UINT8 BPB_Reserved[12];
  UINT8 BS_DrvNum;
  UINT8 BS_Reserved;
  UINT8 BS_BootSig;
  UINT32 BS_VolID;
  UINT8 BS_VolLab[11];
  UINT8 BS_FilSysType[8];
  UINT8 BS_BootCode32[420];
  UINT16 BS_Sign;
} bp_vftm_FAT32_HEADER;
#pragma pack()
EFI_STATUS bp_vftm_get_vftm_assets(EFI_HANDLE image_handle);
EFI_STATUS bp_vftm_check_manifest_authenticity(UINT8 *pk_root,UINT8* sig_root);
EFI_STATUS bp_vftm_check_manifest_content();
bp_vftm_VFTM_ASSETS *bp_vftm_get_assets();
#endif
