Skip to content

Commit 9a12d9d

Browse files
committed
refactor: Move Hitag 1 cmds to protocols.h
1 parent 1ec00c0 commit 9a12d9d

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

armsrc/hitag2.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -448,13 +448,13 @@ void fix_ac_decoding(uint8_t *input, size_t len) {
448448
// looks at number of received bits.
449449
// 0 = collision?
450450
// 32 = good response
451-
static bool hitag_plain(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen, bool hitag_s) {
451+
static bool hitag1_plain(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen, bool hitag_s) {
452452
*txlen = 0;
453453
switch (rxlen) {
454454
case 0: {
455455
// retry waking up card
456456
/*tx[0] = 0xb0; // Rev 3.0*/
457-
tx[0] = 0x30; // Rev 2.0
457+
tx[0] = HITAG1_SET_CC; // Rev 2.0
458458
*txlen = 5;
459459
if (!bCollision) blocknr--;
460460
if (blocknr < 0) {
@@ -472,7 +472,7 @@ static bool hitag_plain(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *tx
472472
uint8_t crc;
473473
if (bCollision) {
474474
// Select card by serial from response
475-
tx[0] = 0x00 | rx[0] >> 5;
475+
tx[0] = HITAG1_SELECT | rx[0] >> 5;
476476
tx[1] = rx[0] << 3 | rx[1] >> 5;
477477
tx[2] = rx[1] << 3 | rx[2] >> 5;
478478
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
498498
}
499499
// read next page of card until done
500500
Dbprintf("Reading page %02u", blocknr);
501-
tx[0] = 0xc0 | blocknr >> 4; // RDPPAGE
501+
tx[0] = HITAG1_RDPPAGE | blocknr >> 4; // RDPPAGE
502502
tx[1] = blocknr << 4;
503503
crc = hitag_crc(tx, 12);
504504
tx[1] |= crc >> 4;
@@ -524,7 +524,7 @@ static bool hitag1_authenticate(uint8_t *rx, const size_t rxlen, uint8_t *tx, si
524524
case 0: {
525525
// retry waking up card
526526
/*tx[0] = 0xb0; // Rev 3.0*/
527-
tx[0] = 0x30; // Rev 2.0
527+
tx[0] = HITAG1_SELECT; // Rev 2.0
528528
*txlen = 5;
529529
if (bCrypto && byte_value <= 0xff) {
530530
// to retry
@@ -554,7 +554,7 @@ static bool hitag1_authenticate(uint8_t *rx, const size_t rxlen, uint8_t *tx, si
554554
// will receive 32 bit encrypted Logdata
555555
} else if (bCrypto) {
556556
// authed, start reading
557-
tx[0] = 0xe0 | blocknr >> 4; // RDCPAGE
557+
tx[0] = HITAG1_RDCPAGE | blocknr >> 4; // RDCPAGE
558558
tx[1] = blocknr << 4;
559559
crc = hitag_crc(tx, 12);
560560
tx[1] |= crc >> 4;
@@ -567,7 +567,7 @@ static bool hitag1_authenticate(uint8_t *rx, const size_t rxlen, uint8_t *tx, si
567567
case 32: {
568568
if (bCollision) {
569569
// Select card by serial from response
570-
tx[0] = 0x00 | rx[0] >> 5;
570+
tx[0] = HITAG1_SELECT | rx[0] >> 5;
571571
tx[1] = rx[0] << 3 | rx[1] >> 5;
572572
tx[2] = rx[1] << 3 | rx[2] >> 5;
573573
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
581581
// will receive 32-bit configuration page
582582
} else if (bSelecting) {
583583
// Initiate auth
584-
tx[0] = 0xa0 | (key_no); // WRCPAGE
584+
tx[0] = HITAG1_WRCPAGE | (key_no); // WRCPAGE
585585
tx[1] = blocknr << 4;
586586
crc = hitag_crc(tx, 12);
587587
tx[1] |= crc >> 4;
@@ -621,7 +621,7 @@ static bool hitag1_authenticate(uint8_t *rx, const size_t rxlen, uint8_t *tx, si
621621
return false;
622622
/*
623623
// read next page of card until done
624-
tx[0] = 0xe0 | blocknr >> 4; // RDCPAGE
624+
tx[0] = HITAG1_RDCPAGE | blocknr >> 4; // RDCPAGE
625625
tx[1] = blocknr << 4;
626626
crc = hitag_crc(tx, 12);
627627
tx[1] |= crc >> 4;
@@ -1820,7 +1820,7 @@ void ReaderHitag(const lf_hitag_data_t *payload, bool ledcontrol) {
18201820
tx = txbuf;
18211821
switch (payload->cmd) {
18221822
case RHT1F_PLAIN: {
1823-
bStop = !hitag_plain(rx, rxlen, tx, &txlen, false);
1823+
bStop = !hitag1_plain(rx, rxlen, tx, &txlen, false);
18241824
break;
18251825
}
18261826
case RHT1F_AUTHENTICATE: {

include/protocols.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -897,18 +897,19 @@ ISO 7816-4 Basic interindustry commands. For command APDU's.
897897
#define CALYPSO_SAM_SV_RELOAD 0x56
898898

899899
// HITAG 1 commands
900-
#define HITAG1_SET_CCNEW 0xC2 // left 5 bits only
900+
#define HITAG1_SET_CC 0x30 // higher 5 bits only
901+
#define HITAG1_SET_CCNEW 0xC8 // higher 5 bits only
901902
#define HITAG1_READ_ID 0x00 // not a real command, consists of 5 bits length, <length> bits partial SN, 8 bits CRC
902-
#define HITAG1_SELECT 0x00 // left 5 bits only, followed by 32 bits SN and 8 bits CRC
903-
#define HITAG1_WRPPAGE 0x80 // left 4 bits only, followed by 8 bits page and 8 bits CRC
904-
#define HITAG1_WRPBLK 0x90 // left 4 bits only, followed by 8 bits block and 8 bits CRC
905-
#define HITAG1_WRCPAGE 0xA0 // left 4 bits only, followed by 8 bits page or key information and 8 bits CRC
906-
#define HITAG1_WRCBLK 0xB0 // left 4 bits only, followed by 8 bits block and 8 bits CRC
907-
#define HITAG1_RDPPAGE 0xC0 // left 4 bits only, followed by 8 bits page and 8 bits CRC
908-
#define HITAG1_RDPBLK 0xD0 // left 4 bits only, followed by 8 bits block and 8 bits CRC
909-
#define HITAG1_RDCPAGE 0xE0 // left 4 bits only, followed by 8 bits page and 8 bits CRC
910-
#define HITAG1_RDCBLK 0xF0 // left 4 bits only, followed by 8 bits block and 8 bits CRC
911-
#define HITAG1_HALT 0x70 // left 4 bits only, followed by 8 bits (dummy) page and 8 bits CRC
903+
#define HITAG1_SELECT 0x00 // higher 5 bits only, followed by 32 bits SN and 8 bits CRC
904+
#define HITAG1_WRPPAGE 0x80 // higher 4 bits only, followed by 8 bits page and 8 bits CRC
905+
#define HITAG1_WRPBLK 0x90 // higher 4 bits only, followed by 8 bits block and 8 bits CRC
906+
#define HITAG1_WRCPAGE 0xA0 // higher 4 bits only, followed by 8 bits page or key information and 8 bits CRC
907+
#define HITAG1_WRCBLK 0xB0 // higher 4 bits only, followed by 8 bits block and 8 bits CRC
908+
#define HITAG1_RDPPAGE 0xC0 // higher 4 bits only, followed by 8 bits page and 8 bits CRC
909+
#define HITAG1_RDPBLK 0xD0 // higher 4 bits only, followed by 8 bits block and 8 bits CRC
910+
#define HITAG1_RDCPAGE 0xE0 // higher 4 bits only, followed by 8 bits page and 8 bits CRC
911+
#define HITAG1_RDCBLK 0xF0 // higher 4 bits only, followed by 8 bits block and 8 bits CRC
912+
#define HITAG1_HALT 0x70 // higher 4 bits only, followed by 8 bits (dummy) page and 8 bits CRC
912913

913914
// HITAG 2 commands
914915
#define HITAG2_START_AUTH 0xC0 // left 5 bits only

0 commit comments

Comments
 (0)