From d19429cb84dd388c90594b32aa2557ea631249f9 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Mon, 23 May 2022 19:56:26 +0200 Subject: [PATCH] Fix handling dynamic files. Signed-off-by: Pol Henarejos --- src/fs/file.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/fs/file.c b/src/fs/file.c index 1ddc0ad..9ea5ebd 100644 --- a/src/fs/file.c +++ b/src/fs/file.c @@ -88,7 +88,7 @@ void process_fci(const file_t *pe) { res_APDU[3] = res_APDU_size-4; } -#define MAX_DYNAMIC_FILES 64 +#define MAX_DYNAMIC_FILES 128 uint16_t dynamic_files = 0; file_t dynamic_file[MAX_DYNAMIC_FILES]; @@ -226,6 +226,9 @@ void scan_flash() { uint16_t fid = flash_read_uint16(base+sizeof(uintptr_t)+sizeof(uintptr_t)); printf("[%x] scan fid %x, len %d\r\n",base,fid,flash_read_uint16(base+sizeof(uintptr_t)+sizeof(uintptr_t)+sizeof(uint16_t))); file_t *file = (file_t *)search_by_fid(fid, NULL, SPECIFY_EF); + if (!file) { + file = file_new(fid); + } if (file) file->data = (uint8_t *)(base+sizeof(uintptr_t)+sizeof(uintptr_t)+sizeof(uint16_t)); if (flash_read_uintptr(base) == 0x0) { @@ -285,22 +288,3 @@ file_t *file_new(uint16_t fid) { //memset((uint8_t *)f->acl, 0x90, sizeof(f->acl)); return f; } - -file_chain_t *add_file_to_chain(file_t *file, file_chain_t **chain) { - if (search_file_chain(file->fid, *chain)) - return NULL; - file_chain_t *fc = (file_chain_t *)malloc(sizeof(file_chain_t)); - fc->file = file; - fc->next = *chain; - *chain = fc; - return fc; -} - -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