From c062c44230012d73f15b8f5df82c7deef7c9b21e Mon Sep 17 00:00:00 2001 From: Markus Walter Date: Mon, 5 Sep 2022 09:52:08 +0200 Subject: [PATCH] Refactor emulator accessor helpers for ISO15693. --- armsrc/iso15693.c | 17 +++++++++++------ armsrc/iso15693.h | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/armsrc/iso15693.c b/armsrc/iso15693.c index 7e4c5c4f3..d4ab6e14e 100644 --- a/armsrc/iso15693.c +++ b/armsrc/iso15693.c @@ -2111,6 +2111,11 @@ void EmlSetMemIso15693(uint8_t count, uint8_t *data, uint32_t offset) { memcpy(emCARD + offset, data, count); } +void EmlGetMemIso15693(uint8_t count, uint8_t *output, uint32_t offset) { + uint8_t *emCARD = BigBuf_get_EM_addr(); + memcpy(output, emCARD + offset, count); +} + // Simulate an ISO15693 TAG, perform anti-collision and then print any reader commands // all demodulation performed in arm rather than host. - greg void SimTagIso15693(uint8_t *uid, uint8_t block_size) { @@ -2272,7 +2277,6 @@ void SimTagIso15693(uint8_t *uid, uint8_t block_size) { resp_readblock[i] = 0; } - uint8_t *emCARD = BigBuf_get_EM_addr(); resp_readblock[0] = 0; // Response flags for (int j = 0; j < block_count; j++) { // where to put the data of the current block @@ -2280,11 +2284,12 @@ void SimTagIso15693(uint8_t *uid, uint8_t block_size) { if (option) { resp_readblock[work_offset] = 0; // Security status } - for (int i = 0; i < block_size; i++) { - // Block data - if (block_size * (block_idx + j + 1) <= CARD_MEMORY_SIZE) { - resp_readblock[work_offset + security_offset + i] = emCARD[block_size * (block_idx + j) + i]; - } else { + // Block data + if (block_size * (block_idx + j + 1) <= CARD_MEMORY_SIZE) { + EmlGetMemIso15693(block_size, resp_readblock + (work_offset + security_offset), + block_size * (block_idx + j)); + } else { + for (int i = 0; i < block_size; i++) { resp_readblock[work_offset + security_offset + i] = 0; } } diff --git a/armsrc/iso15693.h b/armsrc/iso15693.h index 6bd3882bc..f9ba6e9da 100644 --- a/armsrc/iso15693.h +++ b/armsrc/iso15693.h @@ -48,6 +48,7 @@ void AcquireRawAdcSamplesIso15693(void); void ReaderIso15693(iso15_card_select_t *p_card); // ISO15693 reader void EmlClearIso15693(void); void EmlSetMemIso15693(uint8_t count, uint8_t *data, uint32_t offset); +void EmlGetMemIso15693(uint8_t count, uint8_t *output, uint32_t offset); void SimTagIso15693(uint8_t *uid, uint8_t block_size); // simulate an ISO15693 tag void BruteforceIso15693Afi(uint32_t speed); // find an AFI of a tag void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint8_t *data); // send arbitrary commands from CLI