From 3c873d34bc947e6465d42834025a0a2e7d903b10 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 19 Mar 2025 11:26:25 +0100 Subject: [PATCH] style --- armsrc/em4x70.c | 2 +- armsrc/hitag_common.c | 2 +- armsrc/iso14443a.c | 76 +++++++++++++++++++++---------------------- doc/commands.json | 10 +++--- 4 files changed, 46 insertions(+), 44 deletions(-) diff --git a/armsrc/em4x70.c b/armsrc/em4x70.c index 72eb2702c..744e5664c 100644 --- a/armsrc/em4x70.c +++ b/armsrc/em4x70.c @@ -906,7 +906,7 @@ static bool create_legacy_em4x70_bitstream_for_cmd_id(em4x70_command_bitstream_t memset(out_cmd_bitstream, 0, sizeof(em4x70_command_bitstream_t)); out_cmd_bitstream->command = EM4X70_COMMAND_ID; //uint8_t cmd = with_command_parity ? 0x3u : 0x1u; - uint8_t cmd = 0x3u; + uint8_t cmd = 0x3u; result = result && add_nibble_to_bitstream(&out_cmd_bitstream->to_send, cmd, false); out_cmd_bitstream->to_receive.bitcount = 32; if (out_cmd_bitstream->to_send.bitcount != expected_bits_to_send) { diff --git a/armsrc/hitag_common.c b/armsrc/hitag_common.c index 43837486f..d08e090a1 100644 --- a/armsrc/hitag_common.c +++ b/armsrc/hitag_common.c @@ -451,7 +451,7 @@ void hitag_tag_receive_frame(uint8_t *rx, size_t sizeofrx, size_t *rxlen, uint32 // Receive frame, watch for at most T0*EOF periods while (AT91C_BASE_TC1->TC_CV < T0 * HITAG_T_EOF) { - + // Check if edge in modulation is detected if (AT91C_BASE_TC1->TC_SR & next_edge_event) { next_edge_event = next_edge_event ^ (AT91C_TC_LDRAS | AT91C_TC_LDRBS); diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index 3cfdc188c..bdf59f08e 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -3116,48 +3116,48 @@ int iso14_apdu(uint8_t *cmd, uint16_t cmd_len, bool send_chaining, void *data, u if (len == 0) { BigBuf_free(); return 0; // DATA LINK ERROR - } - - - // S-Block WTX - while (len && ((data_bytes[0] & 0xF2) == 0xF2)) { - uint32_t save_iso14a_timeout = iso14a_get_timeout(); - // temporarily increase timeout - iso14a_set_timeout(MAX((data_bytes[1] & 0x3f) * save_iso14a_timeout, MAX_ISO14A_TIMEOUT)); - // Transmit WTX back - // byte1 - WTXM [1..59]. command FWT=FWT*WTXM - data_bytes[1] = data_bytes[1] & 0x3f; // 2 high bits mandatory set to 0b - // now need to fix CRC. - AddCrc14A(data_bytes, len - 2); - // transmit S-Block - ReaderTransmit(data_bytes, len, NULL); - // retrieve the result again (with increased timeout) + } + + + // S-Block WTX + while (len && ((data_bytes[0] & 0xF2) == 0xF2)) { + uint32_t save_iso14a_timeout = iso14a_get_timeout(); + // temporarily increase timeout + iso14a_set_timeout(MAX((data_bytes[1] & 0x3f) * save_iso14a_timeout, MAX_ISO14A_TIMEOUT)); + // Transmit WTX back + // byte1 - WTXM [1..59]. command FWT=FWT*WTXM + data_bytes[1] = data_bytes[1] & 0x3f; // 2 high bits mandatory set to 0b + // now need to fix CRC. + AddCrc14A(data_bytes, len - 2); + // transmit S-Block + ReaderTransmit(data_bytes, len, NULL); + // retrieve the result again (with increased timeout) data_bytes[0] = 0x00; - len = ReaderReceive(data, data_len, parity_array); - data_bytes = data; - // restore timeout - iso14a_set_timeout(save_iso14a_timeout); - } + len = ReaderReceive(data, data_len, parity_array); + data_bytes = data; + // restore timeout + iso14a_set_timeout(save_iso14a_timeout); + } - // if we received an I- or R(ACK)-Block with a block number equal to the - // current block number, toggle the current block number - if (len >= 3 // PCB+CRC = 3 bytes - && ((data_bytes[0] & 0xC0) == 0 // I-Block - || (data_bytes[0] & 0xD0) == 0x80) // R-Block with ACK bit set to 0 - && (data_bytes[0] & 0x01) == iso14_pcb_blocknum) { // equal block numbers - iso14_pcb_blocknum ^= 1; - } + // if we received an I- or R(ACK)-Block with a block number equal to the + // current block number, toggle the current block number + if (len >= 3 // PCB+CRC = 3 bytes + && ((data_bytes[0] & 0xC0) == 0 // I-Block + || (data_bytes[0] & 0xD0) == 0x80) // R-Block with ACK bit set to 0 + && (data_bytes[0] & 0x01) == iso14_pcb_blocknum) { // equal block numbers + iso14_pcb_blocknum ^= 1; + } - // if we received I-block with chaining we need to send ACK and receive another block of data - if (res) { - *res = data_bytes[0]; - } + // if we received I-block with chaining we need to send ACK and receive another block of data + if (res) { + *res = data_bytes[0]; + } - // crc check - if (len >= 3 && !CheckCrc14A(data_bytes, len)) { - BigBuf_free(); - return -1; - } + // crc check + if (len >= 3 && !CheckCrc14A(data_bytes, len)) { + BigBuf_free(); + return -1; + } if (len) { // cut frame byte diff --git a/doc/commands.json b/doc/commands.json index f3a831927..a5fe357a1 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -10102,14 +10102,16 @@ "description": "Simulate Hitag S transponder You need to `lf hitag hts eload` first", "notes": [ "lf hitag hts sim", - "lf hitag hts sim --82xx" + "lf hitag hts sim --82xx", + "lf hitag hts sim -t 30 -> set threshold to 30" ], "offline": false, "options": [ "-h, --help This help", - "-8, --82xx simulate 8268/8310" + "-8, --82xx simulate 8268/8310", + "-t, --threshold set edge detect threshold (def: 127)" ], - "usage": "lf hitag hts sim [-h8]" + "usage": "lf hitag hts sim [-h8] [-t ]" }, "lf hitag hts wrbl": { "command": "lf hitag hts wrbl", @@ -13248,6 +13250,6 @@ "metadata": { "commands_extracted": 761, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2025-03-19T08:33:58" + "extracted_on": "2025-03-19T10:24:44" } }