diff --git a/CHANGELOG.md b/CHANGELOG.md index 61bfdac2d..e3e8d73c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] +- Change NG: iso14a_raw_cmd_t, convert hf 14a raw, dual-mode reader handler (@iceman1001) - Support for flipper ISO15693.nfc dump files (@iceman100) - Change NG: convert CMD_LF_EM4X50_ESET to em4x50_eset_t (@iceman1001) - Change NG: convert CMD_LF_T55XX_SET_CONFIG to t55xx_setconfig_t (@iceman1001) diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index 8e7f0afe2..eb35282ad 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -3790,18 +3790,50 @@ int iso14_apdu(uint8_t *cmd, uint16_t cmd_len, bool send_chaining, void *data, u //----------------------------------------------------------------------------- // Read an ISO 14443a tag. Send out commands and store answers. //----------------------------------------------------------------------------- -// arg0 iso_14a flags -// arg1 high :: number of bits, if you want to send 7bits etc +// NG callers send one iso14a_raw_cmd_t. OLD/MIX callers still pack: +// arg0 iso_14a flags +// arg1 high :: number of bits, if you want to send 7bits etc // low :: len of commandbytes -// arg2 timeout -// d.asBytes command bytes to send +// arg2 high :: wait_us, low :: timeout +// d.asBytes command bytes to send void ReaderIso14443a(PacketCommandNG *c) { - iso14a_command_t param = c->oldarg[0]; - size_t len = c->oldarg[1] & 0xffff; - size_t lenbits = c->oldarg[1] >> 16; - uint32_t timeout = c->oldarg[2] & 0xffffffff; - uint32_t wait_us = c->oldarg[2] >> 32; - uint8_t *cmd = c->data.asBytes; + + iso14a_command_t param; + size_t len, lenbits; + uint32_t timeout, wait_us; + uint8_t *cmd; + + if (c->ng) { + + if (c->length < sizeof(iso14a_raw_cmd_t)) { + reply_ng(CMD_HF_ISO14443A_READER, PM3_EINVARG, NULL, 0); + return; + } + + iso14a_raw_cmd_t *payload = (iso14a_raw_cmd_t *)c->data.asBytes; + + if (payload->len > (c->length - sizeof(iso14a_raw_cmd_t))) { + reply_ng(CMD_HF_ISO14443A_READER, PM3_EINVARG, NULL, 0); + return; + } + + param = payload->flags; + len = payload->len; + lenbits = payload->lenbits; + timeout = payload->timeout; + wait_us = payload->wait_us; + cmd = payload->data; + + } else { + // OLD/MIX callers, still the majority. See doc/new_frame_format.md + param = c->oldarg[0]; + len = c->oldarg[1] & 0xffff; + lenbits = c->oldarg[1] >> 16; + timeout = c->oldarg[2] & 0xffffffff; + wait_us = c->oldarg[2] >> 32; + cmd = c->data.asBytes; + } + uint32_t arg0; uint8_t buf[PM3_CMD_DATA_SIZE_MIX] = {0x00}; diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index a720aece4..c19d06091 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -1710,7 +1710,7 @@ static int CmdHF14ACmdRaw(const char *Cmd) { bool use_schann = arg_get_lit(ctx, 13); int datalen = 0; - uint8_t data[PM3_CMD_DATA_SIZE_MIX] = {0}; + uint8_t data[PM3_CMD_DATA_SIZE - sizeof(iso14a_raw_cmd_t)] = {0}; CLIGetHexWithReturn(ctx, 14, data, &datalen); CLIParserFree(ctx); @@ -1754,11 +1754,9 @@ static int CmdHF14ACmdRaw(const char *Cmd) { flags |= ISO14A_NO_SELECT; } - // 32b MSB encode wait_us, 32b LSB encode timeout - uint64_t argtimeout = 0; + uint32_t timeout_etu = 0; if (wait_us) { flags |= ISO14A_SET_WAIT_US; - argtimeout = ((uint64_t)wait_us) << 32; } if (bTimeout) { @@ -1768,7 +1766,7 @@ static int CmdHF14ACmdRaw(const char *Cmd) { timeout = MAX_TIMEOUT; PrintAndLogEx(INFO, "Set timeout to 40542 seconds (11.26 hours). The max we can wait for response"); } - argtimeout |= 13560000 / 1000 / (8 * 16) * timeout; // timeout in ETUs (time to transfer 1 bit, approx. 9.4 us) + timeout_etu = 13560000 / 1000 / (8 * 16) * timeout; // timeout in ETUs (time to transfer 1 bit, approx. 9.4 us) } if (keep_field_on) { @@ -1795,11 +1793,23 @@ static int CmdHF14ACmdRaw(const char *Cmd) { flags |= ISO14A_NO_RATS; } - // Max buffer is PM3_CMD_DATA_SIZE_MIX - datalen = (datalen > PM3_CMD_DATA_SIZE_MIX) ? PM3_CMD_DATA_SIZE_MIX : datalen; + if (datalen > (int)sizeof(data)) { + datalen = sizeof(data); + } + + uint8_t buf[PM3_CMD_DATA_SIZE] = {0}; + iso14a_raw_cmd_t *payload = (iso14a_raw_cmd_t *)buf; + payload->flags = flags; + payload->timeout = timeout_etu; + payload->wait_us = wait_us; + payload->len = datalen; + payload->lenbits = numbits; + if (datalen) { + memcpy(payload->data, data, datalen); + } clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, flags, (datalen & 0x1FF) | ((uint32_t)(numbits << 16)), argtimeout, data, datalen); + SendCommandNG(CMD_HF_ISO14443A_READER, buf, ISO14A_RAW_LEN(datalen)); if (reply) { int res = 0; diff --git a/include/mifare.h b/include/mifare.h index 2a074b36f..f6a7514f0 100644 --- a/include/mifare.h +++ b/include/mifare.h @@ -111,6 +111,22 @@ typedef enum ISO14A_COMMAND { ISO14A_CLEARTRACE = (1 << 17), } iso14a_command_t; +// CMD_HF_ISO14443A_READER payload. +// Replaces the oldarg packing this command used to ride on: +// arg0 = flags +// arg1 = (lenbits << 16) | len +// arg2 = (wait_us << 32) | timeout +typedef struct { + uint32_t flags; // iso14a_command_t bitmask, needs 18 bits today + uint32_t timeout; // in ETUs, only read when ISO14A_SET_TIMEOUT is set + uint32_t wait_us; // only read when ISO14A_SET_WAIT_US is set + uint16_t len; // bytes in data[] + uint16_t lenbits; // send this many bits instead of whole bytes, 0 = off + uint8_t data[]; +} PACKED iso14a_raw_cmd_t; + +#define ISO14A_RAW_LEN(x) (sizeof(iso14a_raw_cmd_t) + (x)) + typedef struct { uint8_t *response; uint8_t *modulation;