From ad5a4134ec22ecde2f326abfdb93aeefb78e3504 Mon Sep 17 00:00:00 2001 From: douniwan5788 Date: Fri, 23 Aug 2024 19:54:34 +0800 Subject: [PATCH 1/3] refactor: Move Hitag S cmds to protocols.h --- armsrc/hitagS.c | 35 ++++++++++++++++++----------------- include/protocols.h | 13 ++++++++++--- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/armsrc/hitagS.c b/armsrc/hitagS.c index a8563f073..74a6d2a64 100644 --- a/armsrc/hitagS.c +++ b/armsrc/hitagS.c @@ -32,6 +32,7 @@ #include "hitag2/hitag2_crypto.h" #include "lfadc.h" #include "crc.h" +#include #define CRC_PRESET 0xFF #define CRC_POLYNOM 0x1D @@ -455,7 +456,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen, tag.pstate = HT_READY; tag.tstate = HT_NO_OP; - if ((rx[0] & 0xf0) == 0x30) { + if ((rx[0] & 0xf0) == HITAGS_UID_REQ_STD) { if (g_dbglevel >= DBG_EXTENDED) Dbprintf("HT_STANDARD"); @@ -463,7 +464,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen, sof_bits = 1; m = AC2K; } - if ((rx[0] & 0xf0) == 0xc0) { + if ((rx[0] & 0xf0) == HITAGS_UID_REQ_ADV) { tag.mode = HT_ADVANCED; if (g_dbglevel >= DBG_EXTENDED) Dbprintf("HT_ADVANCED"); @@ -472,7 +473,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen, m = AC2K; } - if ((rx[0] & 0xf0) == 0xd0) { + if ((rx[0] & 0xf0) == HITAGS_UID_REQ_FADV) { if (g_dbglevel >= DBG_EXTENDED) Dbprintf("HT_FAST_ADVANCED"); @@ -493,7 +494,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen, DbpString("SELECT"); } - if (check_select(rx, tag.uid) == 1) { + if ((rx[0] & 0xf8) == HITAGS_SELECT && check_select(rx, tag.uid) == 1) { if (g_dbglevel >= DBG_EXTENDED) { DbpString("SELECT match"); } @@ -581,7 +582,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen, } case 40: { if (g_dbglevel >= DBG_EXTENDED) - Dbprintf("WRITE"); + Dbprintf("WRITE DATA"); //data received to be written if (tag.tstate == HT_WRITING_PAGE_DATA) { tag.tstate = HT_NO_OP; @@ -616,7 +617,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen, } case 20: { //write page, write block, read page or read block command received - if ((rx[0] & 0xf0) == 0xc0) { //read page + if ((rx[0] & 0xf0) == HITAGS_READ_PAGE) { //read page //send page data uint8_t page = ((rx[0] & 0x0f) * 16) + ((rx[1] & 0xf0) / 16); *txlen = 32; @@ -647,7 +648,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen, *txlen = 0; } - } else if ((rx[0] & 0xf0) == 0xd0) { //read block + } else if ((rx[0] & 0xf0) == HITAGS_READ_BLOCK) { //read block uint8_t page = ((rx[0] & 0x0f) * 16) + ((rx[1] & 0xf0) / 16); *txlen = 32 * 4; @@ -677,7 +678,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen, *txlen = 0; } - } else if ((rx[0] & 0xf0) == 0x80) { //write page + } else if ((rx[0] & 0xf0) == HITAGS_WRITE_PAGE) { //write page uint8_t page = ((rx[0] & 0x0f) * 16) + ((rx[1] & 0xf0) / 16); @@ -693,7 +694,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen, tag.tstate = HT_WRITING_PAGE_DATA; } - } else if ((rx[0] & 0xf0) == 0x90) { //write block + } else if ((rx[0] & 0xf0) == HITAGS_WRITE_BLOCK) { //write block uint8_t page = ((rx[0] & 0x0f) * 6) + ((rx[1] & 0xf0) / 16); hitagS_set_frame_modulation(); @@ -1236,8 +1237,8 @@ static int selectHitagS(const lf_hitag_data_t *packet, uint8_t *tx, size_t sizeo // UID request FAdvanced 11010 size_t txlen = 0; size_t rxlen = 0; - uint8_t cmd = 0x18; // 11000 UID Request Advanced - txlen = concatbits(tx, txlen, &cmd, 8 - 5, 5); + uint8_t cmd = HITAGS_UID_REQ_ADV; + txlen = concatbits(tx, txlen, &cmd, 0, 5); sendReceiveHitagS(tx, txlen, rx, sizeofrx, &rxlen, t_wait, ledcontrol, true); if (rxlen != 32) { @@ -1253,8 +1254,8 @@ static int selectHitagS(const lf_hitag_data_t *packet, uint8_t *tx, size_t sizeo //select uid txlen = 0; - cmd = 0x00; // 00000 SELECT UID - txlen = concatbits(tx, txlen, &cmd, 8 - 5, 5); + cmd = HITAGS_SELECT; + txlen = concatbits(tx, txlen, &cmd, 0, 5); txlen = concatbits(tx, txlen, rx, 0, 32); uint8_t crc = CRC8Hitag1Bits(tx, txlen); txlen = concatbits(tx, txlen, &crc, 0, 8); @@ -1432,8 +1433,8 @@ void ReadHitagS(const lf_hitag_data_t *payload, bool ledcontrol) { //send read request size_t txlen = 0; - uint8_t cmd = 0x0c; // 1100 READ PAGE - txlen = concatbits(tx, txlen, &cmd, 8 - 4, 4); + uint8_t cmd = HITAGS_READ_PAGE; + txlen = concatbits(tx, txlen, &cmd, 0, 4); uint8_t addr = pageNum; txlen = concatbits(tx, txlen, &addr, 0, 8); uint8_t crc = CRC8Hitag1Bits(tx, txlen); @@ -1537,8 +1538,8 @@ void WritePageHitagS(const lf_hitag_data_t *payload, bool ledcontrol) { //send write page request txlen = 0; - uint8_t cmd = 0x08; // 1000 WRITE PAGE - txlen = concatbits(tx, txlen, &cmd, 8 - 4, 4); + uint8_t cmd = HITAGS_WRITE_PAGE; + txlen = concatbits(tx, txlen, &cmd, 0, 4); uint8_t addr = payload->page; txlen = concatbits(tx, txlen, &addr, 0, 8); diff --git a/include/protocols.h b/include/protocols.h index cbdeacc28..2f8b3d098 100644 --- a/include/protocols.h +++ b/include/protocols.h @@ -918,9 +918,16 @@ ISO 7816-4 Basic interindustry commands. For command APDU's. #define HITAG2_HALT "00" // silence currently authenticated tag // HITAG S commands -#define HITAGS_QUIET 0x70 -//inverted in bit 0 and following 2 bits -#define HITAGS_WRITE_BLOCK 0x90 +#define HITAGS_UID_REQ_STD 0x30 // 00110 UID REQUEST Std +#define HITAGS_UID_REQ_ADV 0xC0 // 11000 UID REQUEST Adv +#define HITAGS_UID_REQ_ADV2 0xC8 // 11001 UID REQUEST Adv +#define HITAGS_UID_REQ_FADV 0xD0 // 11010 UID REQUEST FAdv +#define HITAGS_SELECT 0x00 // 00000 SELECT (UID) +#define HITAGS_READ_PAGE 0xC0 // 1100 READ PAGE +#define HITAGS_READ_BLOCK 0xD0 // 1101 READ BLOCK +#define HITAGS_WRITE_PAGE 0x80 // 1000 WRITE PAGE +#define HITAGS_WRITE_BLOCK 0x90 // 1001 WRITE BLOCK +#define HITAGS_QUIET 0x70 // 0111 QUIET // LTO-CM commands #define LTO_REQ_STANDARD 0x45 From c279f88f137215dfb23377ee1940c64fbcf0b56f Mon Sep 17 00:00:00 2001 From: douniwan5788 Date: Fri, 23 Aug 2024 19:57:28 +0800 Subject: [PATCH 2/3] refactor: Move Hitag 2 cmds to protocols.h --- armsrc/hitag2.c | 23 ++++++++++++----------- client/src/cmdlfhitag.c | 25 ++++++++++++++++--------- include/protocols.h | 11 ++++++----- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c index 30ba0935a..d782e66d8 100644 --- a/armsrc/hitag2.c +++ b/armsrc/hitag2.c @@ -31,6 +31,7 @@ #include "lfdemod.h" #include "commonutil.h" #include "appmain.h" +#include "protocols.h" #define test_bit(data, i) (*(data + (i/8)) >> (7-(i % 8))) & 1 #define set_bit(data, i) *(data + (i/8)) |= (1 << (7-(i % 8))) @@ -210,9 +211,9 @@ static void hitag2_handle_reader_command(uint8_t *rx, const size_t rxlen, uint8_ // Try to find out which command was send by selecting on length (in bits) switch (rxlen) { // Received 11000 from the reader, request for UID, send UID - case 05: { + case 5: { // Always send over the air in the clear plaintext mode - if (rx_air[0] != 0xC0) { + if (rx_air[0] != HITAG2_START_AUTH) { // Unknown frame ? return; } @@ -234,13 +235,13 @@ static void hitag2_handle_reader_command(uint8_t *rx, const size_t rxlen, uint8_ switch (rx[0] & 0xC6) { // Read command: 11xx x00y - case 0xC0: { + case HITAG2_READ_PAGE: { memcpy(tx, tag.sectors[sector], 4); *txlen = 32; break; } // Inverted Read command: 01xx x10y - case 0x44: { + case HITAG2_READ_PAGE_INVERTED: { for (size_t i = 0; i < 4; i++) { tx[i] = tag.sectors[sector][i] ^ 0xff; } @@ -248,7 +249,7 @@ static void hitag2_handle_reader_command(uint8_t *rx, const size_t rxlen, uint8_ break; } // Write command: 10xx x01y - case 0x82: { + case HITAG2_WRITE_PAGE: { // Prepare write, acknowledge by repeating command memcpy(tx, rx, nbytes(rxlen)); *txlen = rxlen; @@ -648,7 +649,7 @@ static bool hitag2_write_page(uint8_t *rx, const size_t rxlen, uint8_t *tx, size switch (writestate) { case WRITE_STATE_START: { *txlen = 10; - tx[0] = 0x82 | (blocknr << 3) | ((blocknr ^ 7) >> 2); + tx[0] = HITAG2_WRITE_PAGE | (blocknr << 3) | ((blocknr ^ 7) >> 2); tx[1] = ((blocknr ^ 7) << 6); writestate = WRITE_STATE_PAGENUM_WRITTEN; break; @@ -656,7 +657,7 @@ static bool hitag2_write_page(uint8_t *rx, const size_t rxlen, uint8_t *tx, size case WRITE_STATE_PAGENUM_WRITTEN: { // Check if page number was received correctly if ((rxlen == 10) - && (rx[0] == (0x82 | (blocknr << 3) | ((blocknr ^ 7) >> 2))) + && (rx[0] == (HITAG2_WRITE_PAGE | (blocknr << 3) | ((blocknr ^ 7) >> 2))) && (rx[1] == (((blocknr & 0x3) ^ 0x3) << 6))) { *txlen = 32; @@ -748,7 +749,7 @@ static bool hitag2_password(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t } *txlen = 10; - tx[0] = 0xC0 | (blocknr << 3) | ((blocknr ^ 7) >> 2); + tx[0] = HITAG2_READ_PAGE | (blocknr << 3) | ((blocknr ^ 7) >> 2); tx[1] = ((blocknr ^ 7) << 6); } } @@ -871,7 +872,7 @@ static bool hitag2_crypto(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t * return false; } else { *txlen = 10; - tx[0] = 0xc0 | (blocknr << 3) | ((blocknr ^ 7) >> 2); + tx[0] = HITAG2_READ_PAGE | (blocknr << 3) | ((blocknr ^ 7) >> 2); tx[1] = ((blocknr ^ 7) << 6); } } @@ -957,7 +958,7 @@ static bool hitag2_authenticate(uint8_t *rx, const size_t rxlen, uint8_t *tx, si DBG Dbprintf("Sending read block %u", blocknr); *txlen = 10; - tx[0] = 0xc0 | (blocknr << 3) | ((blocknr ^ 7) >> 2); + tx[0] = HITAG2_READ_PAGE | (blocknr << 3) | ((blocknr ^ 7) >> 2); tx[1] = ((blocknr ^ 7) << 6); } } @@ -2628,7 +2629,7 @@ int ht2_read_uid(uint8_t *uid, bool ledcontrol, bool send_answer, bool keep_fiel // start AUTH command size_t txlen = 5; - uint8_t tx[1] = {0xC0}; + uint8_t tx[0] = {HITAG2_START_AUTH}; // Transmit as reader ht2_send(turn_on, &command_start, &command_duration, &response_start, tx, txlen, false); diff --git a/client/src/cmdlfhitag.c b/client/src/cmdlfhitag.c index 0fc537527..eb7ab3eac 100644 --- a/client/src/cmdlfhitag.c +++ b/client/src/cmdlfhitag.c @@ -522,6 +522,13 @@ bool hitag2_get_plain(uint8_t *plain, uint8_t *plen) { return false; } +// HITAG 2 commands +#define HITAG2_BINSTR_START_AUTH "11000" // get UID and/or start the authentication process +#define HITAG2_BINSTR_READ_PAGE "11" // read page after auth +#define HITAG2_BINSTR_READ_PAGE_INVERTED "01" // as read page but all bits inverted +#define HITAG2_BINSTR_WRITE_PAGE "10" // write page after auth +#define HITAG2_BINSTR_HALT "00" // silence currently authenticated tag + static uint8_t hitag2_get_page(const char *bs) { if ((memcmp(bs + 2, "000", 3) == 0) && (memcmp(bs + 2 + 3 + 2, "111", 3) == 0)) { return 0; @@ -578,24 +585,24 @@ void hitag2_annotate_plain(char *exp, size_t size, const uint8_t *cmd, uint8_t c break; } case 10: { - if (memcmp(binstr, HITAG2_HALT, 2) == 0) { + if (memcmp(binstr, HITAG2_BINSTR_HALT, 2) == 0) { snprintf(exp, size, " "); break; } uint8_t page = hitag2_get_page(binstr); - if (memcmp(binstr, HITAG2_READ_PAGE, 2) == 0) { + if (memcmp(binstr, HITAG2_BINSTR_READ_PAGE, 2) == 0) { snprintf(exp, size, "READ PAGE (" _MAGENTA_("%u") ")", page); break; } - if (memcmp(binstr, HITAG2_READ_PAGE_INVERTED, 2) == 0) { + if (memcmp(binstr, HITAG2_BINSTR_READ_PAGE_INVERTED, 2) == 0) { snprintf(exp, size, "READ PAGE INV (" _MAGENTA_("%u") ")", page); break; } - if (memcmp(binstr, HITAG2_WRITE_PAGE, 2) == 0) { + if (memcmp(binstr, HITAG2_BINSTR_WRITE_PAGE, 2) == 0) { snprintf(exp, size, "WRITE PAGE (" _MAGENTA_("%u") ")", page); break; } @@ -654,7 +661,7 @@ void annotateHitag2(char *exp, size_t size, const uint8_t *cmd, uint8_t cmdsize, case 5: { annotateHitag2_init(); - if (memcmp(binstr, HITAG2_START_AUTH, 5) == 0) { + if (memcmp(binstr, HITAG2_BINSTR_START_AUTH, 5) == 0) { snprintf(exp, size, "START AUTH"); _ht2state.state = STATE_START_AUTH; } else { @@ -669,7 +676,7 @@ void annotateHitag2(char *exp, size_t size, const uint8_t *cmd, uint8_t cmdsize, break; } - if (memcmp(binstr, HITAG2_HALT, 2) == 0) { + if (memcmp(binstr, HITAG2_BINSTR_HALT, 2) == 0) { snprintf(exp, size, "HALT"); _ht2state.state = STATE_HALT; break; @@ -677,17 +684,17 @@ void annotateHitag2(char *exp, size_t size, const uint8_t *cmd, uint8_t cmdsize, uint8_t page = hitag2_get_page(binstr); - if (memcmp(binstr, HITAG2_READ_PAGE, 2) == 0) { + if (memcmp(binstr, HITAG2_BINSTR_READ_PAGE, 2) == 0) { snprintf(exp, size, "READ PAGE (" _MAGENTA_("%u") ")", page); break; } - if (memcmp(binstr, HITAG2_READ_PAGE_INVERTED, 2) == 0) { + if (memcmp(binstr, HITAG2_BINSTR_READ_PAGE_INVERTED, 2) == 0) { snprintf(exp, size, "READ PAGE INV (" _MAGENTA_("%u") ")", page); break; } - if (memcmp(binstr, HITAG2_WRITE_PAGE, 2) == 0) { + if (memcmp(binstr, HITAG2_BINSTR_WRITE_PAGE, 2) == 0) { snprintf(exp, size, "WRITE PAGE (" _MAGENTA_("%u") ")", page); break; } diff --git a/include/protocols.h b/include/protocols.h index 2f8b3d098..d44a8151c 100644 --- a/include/protocols.h +++ b/include/protocols.h @@ -911,11 +911,12 @@ ISO 7816-4 Basic interindustry commands. For command APDU's. #define HITAG1_HALT 0x70 // left 4 bits only, followed by 8 bits (dummy) page and 8 bits CRC // HITAG 2 commands -#define HITAG2_START_AUTH "11000" // get UID and/or start the authentication process -#define HITAG2_READ_PAGE "11" // read page after auth -#define HITAG2_READ_PAGE_INVERTED "01" // as read page but all bits inverted -#define HITAG2_WRITE_PAGE "10" // write page after auth -#define HITAG2_HALT "00" // silence currently authenticated tag +#define HITAG2_START_AUTH 0xC0 // left 5 bits only +#define HITAG2_READ_PAGE 0xC0 // page number in bits 5 to 3, page number inverted in bit 0 and following 2 bits +#define HITAG2_READ_PAGE_INVERTED 0x44 // page number in bits 5 to 3, page number inverted in bit 0 and following 2 bits +#define HITAG2_WRITE_PAGE 0x82 // page number in bits 5 to 3, page number inverted in bit 0 and following 2 bits +#define HITAG2_HALT 0x00 // left 5 bits only + // HITAG S commands #define HITAGS_UID_REQ_STD 0x30 // 00110 UID REQUEST Std From 75420482e422e688663874a832f66e9fab7de00a Mon Sep 17 00:00:00 2001 From: douniwan5788 Date: Fri, 23 Aug 2024 19:58:44 +0800 Subject: [PATCH 3/3] refactor: Move Hitag 1 cmds to protocols.h --- armsrc/hitag2.c | 22 +++++++++++----------- include/protocols.h | 23 ++++++++++++----------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c index d782e66d8..fb5e706b2 100644 --- a/armsrc/hitag2.c +++ b/armsrc/hitag2.c @@ -448,13 +448,13 @@ void fix_ac_decoding(uint8_t *input, size_t len) { // looks at number of received bits. // 0 = collision? // 32 = good response -static bool hitag_plain(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen, bool hitag_s) { +static bool hitag1_plain(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen, bool hitag_s) { *txlen = 0; switch (rxlen) { case 0: { // retry waking up card /*tx[0] = 0xb0; // Rev 3.0*/ - tx[0] = 0x30; // Rev 2.0 + tx[0] = HITAG1_SET_CC; // Rev 2.0 *txlen = 5; if (!bCollision) blocknr--; if (blocknr < 0) { @@ -472,7 +472,7 @@ static bool hitag_plain(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *tx uint8_t crc; if (bCollision) { // Select card by serial from response - tx[0] = 0x00 | rx[0] >> 5; + tx[0] = HITAG1_SELECT | rx[0] >> 5; tx[1] = rx[0] << 3 | rx[1] >> 5; tx[2] = rx[1] << 3 | rx[2] >> 5; tx[3] = rx[2] << 3 | rx[3] >> 5; @@ -498,7 +498,7 @@ static bool hitag_plain(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *tx } // read next page of card until done Dbprintf("Reading page %02u", blocknr); - tx[0] = 0xc0 | blocknr >> 4; // RDPPAGE + tx[0] = HITAG1_RDPPAGE | blocknr >> 4; // RDPPAGE tx[1] = blocknr << 4; crc = hitag_crc(tx, 12); tx[1] |= crc >> 4; @@ -524,7 +524,7 @@ static bool hitag1_authenticate(uint8_t *rx, const size_t rxlen, uint8_t *tx, si case 0: { // retry waking up card /*tx[0] = 0xb0; // Rev 3.0*/ - tx[0] = 0x30; // Rev 2.0 + tx[0] = HITAG1_SELECT; // Rev 2.0 *txlen = 5; if (bCrypto && byte_value <= 0xff) { // to retry @@ -554,7 +554,7 @@ static bool hitag1_authenticate(uint8_t *rx, const size_t rxlen, uint8_t *tx, si // will receive 32 bit encrypted Logdata } else if (bCrypto) { // authed, start reading - tx[0] = 0xe0 | blocknr >> 4; // RDCPAGE + tx[0] = HITAG1_RDCPAGE | blocknr >> 4; // RDCPAGE tx[1] = blocknr << 4; crc = hitag_crc(tx, 12); tx[1] |= crc >> 4; @@ -567,7 +567,7 @@ static bool hitag1_authenticate(uint8_t *rx, const size_t rxlen, uint8_t *tx, si case 32: { if (bCollision) { // Select card by serial from response - tx[0] = 0x00 | rx[0] >> 5; + tx[0] = HITAG1_SELECT | rx[0] >> 5; tx[1] = rx[0] << 3 | rx[1] >> 5; tx[2] = rx[1] << 3 | rx[2] >> 5; tx[3] = rx[2] << 3 | rx[3] >> 5; @@ -581,7 +581,7 @@ static bool hitag1_authenticate(uint8_t *rx, const size_t rxlen, uint8_t *tx, si // will receive 32-bit configuration page } else if (bSelecting) { // Initiate auth - tx[0] = 0xa0 | (key_no); // WRCPAGE + tx[0] = HITAG1_WRCPAGE | (key_no); // WRCPAGE tx[1] = blocknr << 4; crc = hitag_crc(tx, 12); tx[1] |= crc >> 4; @@ -621,7 +621,7 @@ static bool hitag1_authenticate(uint8_t *rx, const size_t rxlen, uint8_t *tx, si return false; /* // read next page of card until done - tx[0] = 0xe0 | blocknr >> 4; // RDCPAGE + tx[0] = HITAG1_RDCPAGE | blocknr >> 4; // RDCPAGE tx[1] = blocknr << 4; crc = hitag_crc(tx, 12); tx[1] |= crc >> 4; @@ -1820,7 +1820,7 @@ void ReaderHitag(const lf_hitag_data_t *payload, bool ledcontrol) { tx = txbuf; switch (payload->cmd) { case RHT1F_PLAIN: { - bStop = !hitag_plain(rx, rxlen, tx, &txlen, false); + bStop = !hitag1_plain(rx, rxlen, tx, &txlen, false); break; } case RHT1F_AUTHENTICATE: { @@ -2629,7 +2629,7 @@ int ht2_read_uid(uint8_t *uid, bool ledcontrol, bool send_answer, bool keep_fiel // start AUTH command size_t txlen = 5; - uint8_t tx[0] = {HITAG2_START_AUTH}; + uint8_t tx[] = {HITAG2_START_AUTH}; // Transmit as reader ht2_send(turn_on, &command_start, &command_duration, &response_start, tx, txlen, false); diff --git a/include/protocols.h b/include/protocols.h index d44a8151c..23ee85f6b 100644 --- a/include/protocols.h +++ b/include/protocols.h @@ -897,18 +897,19 @@ ISO 7816-4 Basic interindustry commands. For command APDU's. #define CALYPSO_SAM_SV_RELOAD 0x56 // HITAG 1 commands -#define HITAG1_SET_CCNEW 0xC2 // left 5 bits only +#define HITAG1_SET_CC 0x30 // higher 5 bits only +#define HITAG1_SET_CCNEW 0xC8 // higher 5 bits only #define HITAG1_READ_ID 0x00 // not a real command, consists of 5 bits length, bits partial SN, 8 bits CRC -#define HITAG1_SELECT 0x00 // left 5 bits only, followed by 32 bits SN and 8 bits CRC -#define HITAG1_WRPPAGE 0x80 // left 4 bits only, followed by 8 bits page and 8 bits CRC -#define HITAG1_WRPBLK 0x90 // left 4 bits only, followed by 8 bits block and 8 bits CRC -#define HITAG1_WRCPAGE 0xA0 // left 4 bits only, followed by 8 bits page or key information and 8 bits CRC -#define HITAG1_WRCBLK 0xB0 // left 4 bits only, followed by 8 bits block and 8 bits CRC -#define HITAG1_RDPPAGE 0xC0 // left 4 bits only, followed by 8 bits page and 8 bits CRC -#define HITAG1_RDPBLK 0xD0 // left 4 bits only, followed by 8 bits block and 8 bits CRC -#define HITAG1_RDCPAGE 0xE0 // left 4 bits only, followed by 8 bits page and 8 bits CRC -#define HITAG1_RDCBLK 0xF0 // left 4 bits only, followed by 8 bits block and 8 bits CRC -#define HITAG1_HALT 0x70 // left 4 bits only, followed by 8 bits (dummy) page and 8 bits CRC +#define HITAG1_SELECT 0x00 // higher 5 bits only, followed by 32 bits SN and 8 bits CRC +#define HITAG1_WRPPAGE 0x80 // higher 4 bits only, followed by 8 bits page and 8 bits CRC +#define HITAG1_WRPBLK 0x90 // higher 4 bits only, followed by 8 bits block and 8 bits CRC +#define HITAG1_WRCPAGE 0xA0 // higher 4 bits only, followed by 8 bits page or key information and 8 bits CRC +#define HITAG1_WRCBLK 0xB0 // higher 4 bits only, followed by 8 bits block and 8 bits CRC +#define HITAG1_RDPPAGE 0xC0 // higher 4 bits only, followed by 8 bits page and 8 bits CRC +#define HITAG1_RDPBLK 0xD0 // higher 4 bits only, followed by 8 bits block and 8 bits CRC +#define HITAG1_RDCPAGE 0xE0 // higher 4 bits only, followed by 8 bits page and 8 bits CRC +#define HITAG1_RDCBLK 0xF0 // higher 4 bits only, followed by 8 bits block and 8 bits CRC +#define HITAG1_HALT 0x70 // higher 4 bits only, followed by 8 bits (dummy) page and 8 bits CRC // HITAG 2 commands #define HITAG2_START_AUTH 0xC0 // left 5 bits only