Rename CCID_ codes to PICOKEY_

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2024-11-05 18:21:24 +01:00
parent 242e357a74
commit 6625678c30
14 changed files with 95 additions and 95 deletions

View File

@@ -332,7 +332,7 @@ file_t *search_dynamic_file(uint16_t fid) {
int delete_dynamic_file(file_t *f) {
if (f == NULL) {
return CCID_ERR_FILE_NOT_FOUND;
return PICOKEY_ERR_FILE_NOT_FOUND;
}
for (int i = 0; i < dynamic_files; i++) {
if (dynamic_file[i].fid == f->fid) {
@@ -340,10 +340,10 @@ int delete_dynamic_file(file_t *f) {
memcpy(&dynamic_file[j - 1], &dynamic_file[j], sizeof(file_t));
}
dynamic_files--;
return CCID_OK;
return PICOKEY_OK;
}
}
return CCID_ERR_FILE_NOT_FOUND;
return PICOKEY_ERR_FILE_NOT_FOUND;
}
file_t *file_new(uint16_t fid) {
@@ -396,7 +396,7 @@ uint16_t meta_find(uint16_t fid, uint8_t **out) {
int meta_delete(uint16_t fid) {
file_t *ef = search_file(EF_META);
if (!ef) {
return CCID_ERR_FILE_NOT_FOUND;
return PICOKEY_ERR_FILE_NOT_FOUND;
}
uint16_t tag = 0x0;
uint8_t *tag_data = NULL, *p = NULL;
@@ -425,21 +425,21 @@ int meta_delete(uint16_t fid) {
}
int r = file_put_data(ef, fdata, new_len);
free(fdata);
if (r != CCID_OK) {
return CCID_EXEC_ERROR;
if (r != PICOKEY_OK) {
return PICOKEY_EXEC_ERROR;
}
}
low_flash_available();
break;
}
}
return CCID_OK;
return PICOKEY_OK;
}
int meta_add(uint16_t fid, const uint8_t *data, uint16_t len) {
int r;
file_t *ef = search_file(EF_META);
if (!ef) {
return CCID_ERR_FILE_NOT_FOUND;
return PICOKEY_ERR_FILE_NOT_FOUND;
}
uint16_t ef_size = file_get_size(ef);
uint8_t *fdata = (uint8_t *) calloc(1, ef_size);
@@ -459,10 +459,10 @@ int meta_add(uint16_t fid, const uint8_t *data, uint16_t len) {
memcpy(p - tag_len + 2, data, len);
r = file_put_data(ef, fdata, ef_size);
free(fdata);
if (r != CCID_OK) {
return CCID_EXEC_ERROR;
if (r != PICOKEY_OK) {
return PICOKEY_EXEC_ERROR;
}
return CCID_OK;
return PICOKEY_OK;
}
else { //needs reallocation
uint8_t *tpos = p - asn1_len_tag(tag, tag_len);
@@ -477,7 +477,7 @@ int meta_add(uint16_t fid, const uint8_t *data, uint16_t len) {
}
else {
free(fdata);
return CCID_ERR_MEMORY_FATAL;
return PICOKEY_ERR_MEMORY_FATAL;
}
}
uint8_t *f = fdata + meta_offset;
@@ -488,10 +488,10 @@ int meta_add(uint16_t fid, const uint8_t *data, uint16_t len) {
memcpy(f, data, len);
r = file_put_data(ef, fdata, ef_size);
free(fdata);
if (r != CCID_OK) {
return CCID_EXEC_ERROR;
if (r != PICOKEY_OK) {
return PICOKEY_EXEC_ERROR;
}
return CCID_OK;
return PICOKEY_OK;
}
}
}
@@ -504,10 +504,10 @@ int meta_add(uint16_t fid, const uint8_t *data, uint16_t len) {
memcpy(f, data, len);
r = file_put_data(ef, fdata, ef_size + (uint16_t)asn1_len_tag(fid & 0x1f, len + 2));
free(fdata);
if (r != CCID_OK) {
return CCID_EXEC_ERROR;
if (r != PICOKEY_OK) {
return PICOKEY_EXEC_ERROR;
}
return CCID_OK;
return PICOKEY_OK;
}
bool file_has_data(file_t *f) {
@@ -516,15 +516,15 @@ bool file_has_data(file_t *f) {
int delete_file(file_t *ef) {
if (ef == NULL) {
return CCID_OK;
return PICOKEY_OK;
}
meta_delete(ef->fid);
if (flash_clear_file(ef) != CCID_OK) {
return CCID_EXEC_ERROR;
if (flash_clear_file(ef) != PICOKEY_OK) {
return PICOKEY_EXEC_ERROR;
}
if (delete_dynamic_file(ef) != CCID_OK) {
return CCID_EXEC_ERROR;
if (delete_dynamic_file(ef) != PICOKEY_OK) {
return PICOKEY_EXEC_ERROR;
}
low_flash_available();
return CCID_OK;
return PICOKEY_OK;
}

View File

@@ -128,7 +128,7 @@ uintptr_t allocate_free_addr(uint16_t size, bool persistent) {
int flash_clear_file(file_t *file) {
if (file == NULL || file->data == NULL) {
return CCID_OK;
return PICOKEY_OK;
}
uintptr_t base_addr =
(uintptr_t)(file->data - sizeof(uintptr_t) - sizeof(uint16_t) - sizeof(uintptr_t));
@@ -144,18 +144,18 @@ int flash_clear_file(file_t *file) {
flash_program_uintptr(base_addr + sizeof(uintptr_t), 0);
file->data = NULL;
//printf("na %lx->%lx\n",prev_addr,flash_read_uintptr(prev_addr));
return CCID_OK;
return PICOKEY_OK;
}
int flash_write_data_to_file_offset(file_t *file, const uint8_t *data, uint16_t len,
uint16_t offset) {
if (!file) {
return CCID_ERR_NULL_PARAM;
return PICOKEY_ERR_NULL_PARAM;
}
uint16_t size_file_flash = file->data ? flash_read_uint16((uintptr_t) file->data) : 0;
uint8_t *old_data = NULL;
if (offset + len > FLASH_SECTOR_SIZE || offset > size_file_flash) {
return CCID_ERR_NO_MEMORY;
return PICOKEY_ERR_NO_MEMORY;
}
if (file->data) { //already in flash
if (offset + len <= size_file_flash) { //it fits, no need to move it
@@ -163,7 +163,7 @@ int flash_write_data_to_file_offset(file_t *file, const uint8_t *data, uint16_t
if (data) {
flash_program_block((uintptr_t) file->data + sizeof(uint16_t) + offset, data, len);
}
return CCID_OK;
return PICOKEY_OK;
}
else { //we clear the old file
flash_clear_file(file);
@@ -180,7 +180,7 @@ int flash_write_data_to_file_offset(file_t *file, const uint8_t *data, uint16_t
uintptr_t new_addr = allocate_free_addr(len, (file->type & FILE_PERSISTENT) == FILE_PERSISTENT);
//printf("na %x\n",new_addr);
if (new_addr == 0x0) {
return CCID_ERR_NO_MEMORY;
return PICOKEY_ERR_NO_MEMORY;
}
file->data = (uint8_t *) new_addr + sizeof(uintptr_t) + sizeof(uint16_t) + sizeof(uintptr_t); //next addr+fid+prev addr
flash_program_halfword(new_addr + sizeof(uintptr_t) + sizeof(uintptr_t), file->fid);
@@ -191,7 +191,7 @@ int flash_write_data_to_file_offset(file_t *file, const uint8_t *data, uint16_t
if (old_data) {
free(old_data);
}
return CCID_OK;
return PICOKEY_OK;
}
int flash_write_data_to_file(file_t *file, const uint8_t *data, uint16_t len) {
return flash_write_data_to_file_offset(file, data, len, 0);

View File

@@ -224,24 +224,24 @@ int flash_program_block(uintptr_t addr, const uint8_t *data, size_t len) {
page_flash_t *p = NULL;
if (!data || len == 0) {
return CCID_ERR_NULL_PARAM;
return PICOKEY_ERR_NULL_PARAM;
}
mutex_enter_blocking(&mtx_flash);
if (ready_pages == TOTAL_FLASH_PAGES) {
mutex_exit(&mtx_flash);
printf("ERROR: ALL FLASH PAGES CACHED\n");
return CCID_ERR_NO_MEMORY;
return PICOKEY_ERR_NO_MEMORY;
}
if (!(p = find_free_page(addr))) {
mutex_exit(&mtx_flash);
printf("ERROR: FLASH CANNOT FIND A PAGE (rare error)\n");
return CCID_ERR_MEMORY_FATAL;
return PICOKEY_ERR_MEMORY_FATAL;
}
memcpy(&p->page[addr & (FLASH_SECTOR_SIZE - 1)], data, len);
//printf("Flash: modified page %X with data %x at [%x]\n",(uintptr_t)addr,(uintptr_t)data,addr&(FLASH_SECTOR_SIZE-1));
mutex_exit(&mtx_flash);
return CCID_OK;
return PICOKEY_OK;
}
int flash_program_halfword(uintptr_t addr, uint16_t data) {
@@ -305,19 +305,19 @@ int flash_erase_page(uintptr_t addr, size_t page_size) {
if (ready_pages == TOTAL_FLASH_PAGES) {
mutex_exit(&mtx_flash);
printf("ERROR: ALL FLASH PAGES CACHED\n");
return CCID_ERR_NO_MEMORY;
return PICOKEY_ERR_NO_MEMORY;
}
if (!(p = find_free_page(addr))) {
printf("ERROR: FLASH CANNOT FIND A PAGE (rare error)\n");
mutex_exit(&mtx_flash);
return CCID_ERR_MEMORY_FATAL;
return PICOKEY_ERR_MEMORY_FATAL;
}
p->erase = true;
p->ready = false;
p->page_size = page_size;
mutex_exit(&mtx_flash);
return CCID_OK;
return PICOKEY_OK;
}
bool flash_check_blank(const uint8_t *p_start, size_t size) {

View File

@@ -24,7 +24,7 @@ phy_data_t phy_data;
int phy_serialize_data(const phy_data_t *phy, uint8_t *data, uint16_t *len) {
if (!phy || !data || !len) {
return CCID_ERR_NULL_PARAM;
return PICOKEY_ERR_NULL_PARAM;
}
uint8_t *p = data;
if (phy->vidpid_present) {
@@ -46,12 +46,12 @@ int phy_serialize_data(const phy_data_t *phy, uint8_t *data, uint16_t *len) {
*p++ = phy->opts >> 8;
*p++ = phy->opts & 0xff;
*len = p - data;
return CCID_OK;
return PICOKEY_OK;
}
#include <stdio.h>
int phy_unserialize_data(const uint8_t *data, uint16_t len, phy_data_t *phy) {
if (!phy || !data || !len) {
return CCID_ERR_NULL_PARAM;
return PICOKEY_ERR_NULL_PARAM;
}
memset(phy, 0, sizeof(phy_data_t));
const uint8_t *p = data;
@@ -80,7 +80,7 @@ int phy_unserialize_data(const uint8_t *data, uint16_t len, phy_data_t *phy) {
break;
}
}
return CCID_OK;
return PICOKEY_OK;
}
int phy_init() {
@@ -89,11 +89,11 @@ int phy_init() {
const uint8_t *data = file_get_data(ef_phy);
DEBUG_DATA(data, file_get_size(ef_phy));
int ret = phy_unserialize_data(data, file_get_size(ef_phy), &phy_data);
if (ret != CCID_OK) {
if (ret != PICOKEY_OK) {
return ret;
}
}
return CCID_OK;
return PICOKEY_OK;
}
#endif