From d32620710e97cb8b56094c85157df6e9c4737213 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Mon, 21 Feb 2022 12:20:39 +0100 Subject: [PATCH] Adding file chains for CC, CE and CD. Signed-off-by: Pol Henarejos --- file.c | 21 ++++++++++++++++++++- file.h | 9 ++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/file.c b/file.c index 3950ec5..a45d8ae 100644 --- a/file.c +++ b/file.c @@ -133,6 +133,7 @@ file_t *file_sopin = NULL; file_t *file_retries_sopin = NULL; file_chain_t *ef_prkdf = NULL; +file_chain_t *ef_kf = NULL; file_chain_t *ef_pukdf = NULL; file_chain_t *ef_cdf = NULL; @@ -278,12 +279,21 @@ void scan_flash() { break; uint16_t fid = flash_read_uint16(base+sizeof(uintptr_t)); + printf("scan fid %x\r\n",fid); file_t *file = (file_t *)search_by_fid(fid, NULL, SPECIFY_EF); if (!file) { if ((fid & 0xff00) == (KEY_PREFIX << 8)) { + file = file_new(fid); + add_file_to_chain(file, &ef_kf); + } + else if ((fid & 0xff00) == (PRKD_PREFIX << 8)) { file = file_new(fid); add_file_to_chain(file, &ef_prkdf); } + else if ((fid & 0xff00) == (CD_PREFIX << 8)) { + file = file_new(fid); + add_file_to_chain(file, &ef_cdf); + } else { TU_LOG1("SCAN FOUND ORPHAN FILE: %x\r\n",fid); continue; @@ -387,7 +397,7 @@ file_t *file_new(uint16_t fid) { .acl = {0} }; memcpy(f, &file, sizeof(file_t)); - memset((uint8_t *)f->acl, 0x90, sizeof(f->acl)); + //memset((uint8_t *)f->acl, 0x90, sizeof(f->acl)); return f; } @@ -397,4 +407,13 @@ file_chain_t *add_file_to_chain(file_t *file, file_chain_t **chain) { f_chain->next = *chain; *chain = f_chain; return f_chain; +} + +file_t *search_file_chain(uint16_t fid, file_chain_t *chain) { + for (file_chain_t *fc = chain; fc; fc = fc->next) { + if (fid == fc->file->fid) { + return fc->file; + } + } + return NULL; } \ No newline at end of file diff --git a/file.h b/file.h index e918375..df71852 100644 --- a/file.h +++ b/file.h @@ -87,11 +87,14 @@ extern uint16_t file_read_uint16(const uint8_t *addr); extern uint8_t file_read_uint8(const uint8_t *addr); extern file_t *file_new(uint16_t); -extern file_chain_t *ef_prkdf; -extern file_chain_t *ef_pukdf; -extern file_chain_t *ef_cdf; +extern file_chain_t *ef_prkdf; //key description +extern file_chain_t *ef_kf; //key blob +extern file_chain_t *ef_pukdf; //cvc csr +extern file_chain_t *ef_cdf; //ce extern file_chain_t *add_file_to_chain(file_t *file, file_chain_t **chain); +extern file_t *search_file_chain(uint16_t fid, file_chain_t *chain); +extern bool isUserAuthenticated; #endif