Adding file chains for CC, CE and CD.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2022-02-21 12:20:39 +01:00
parent fe429bf5af
commit d32620710e
2 changed files with 26 additions and 4 deletions

21
file.c
View File

@@ -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;
}

9
file.h
View File

@@ -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