mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 13:00:42 -07:00
spaces
This commit is contained in:
parent
71160ddbca
commit
9c2736d1eb
14 changed files with 273 additions and 273 deletions
|
@ -673,7 +673,7 @@ static bool hitag2_read_uid(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t
|
||||||
void SniffHitag(uint32_t type) {
|
void SniffHitag(uint32_t type) {
|
||||||
|
|
||||||
StopTicks();
|
StopTicks();
|
||||||
|
|
||||||
int frame_count;
|
int frame_count;
|
||||||
int response;
|
int response;
|
||||||
int overflow;
|
int overflow;
|
||||||
|
@ -719,14 +719,14 @@ void SniffHitag(uint32_t type) {
|
||||||
|
|
||||||
// Disable timer during configuration
|
// Disable timer during configuration
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
|
|
||||||
// TC1: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
|
// TC1: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
|
||||||
// external trigger rising edge, load RA on rising edge of TIOA.
|
// external trigger rising edge, load RA on rising edge of TIOA.
|
||||||
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK | AT91C_TC_ETRGEDG_BOTH | AT91C_TC_ABETRG | AT91C_TC_LDRA_BOTH;
|
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK | AT91C_TC_ETRGEDG_BOTH | AT91C_TC_ABETRG | AT91C_TC_LDRA_BOTH;
|
||||||
|
|
||||||
// Enable and reset counter
|
// Enable and reset counter
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||||
|
|
||||||
// synchronized startup procedure
|
// synchronized startup procedure
|
||||||
while (AT91C_BASE_TC1->TC_CV > 0) {}; // wait until TC0 returned to zero
|
while (AT91C_BASE_TC1->TC_CV > 0) {}; // wait until TC0 returned to zero
|
||||||
|
|
||||||
|
@ -841,7 +841,7 @@ void SniffHitag(uint32_t type) {
|
||||||
if (rxlen > 0) {
|
if (rxlen > 0) {
|
||||||
frame_count++;
|
frame_count++;
|
||||||
LogTrace(rx, nbytes(rxlen), response, 0, NULL, reader_frame);
|
LogTrace(rx, nbytes(rxlen), response, 0, NULL, reader_frame);
|
||||||
|
|
||||||
// Check if we recognize a valid authentication attempt
|
// Check if we recognize a valid authentication attempt
|
||||||
if (nbytes(rxlen) == 8) {
|
if (nbytes(rxlen) == 8) {
|
||||||
// Store the authentication attempt
|
// Store the authentication attempt
|
||||||
|
@ -874,21 +874,21 @@ void SniffHitag(uint32_t type) {
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
set_tracing(false);
|
set_tracing(false);
|
||||||
|
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
|
|
||||||
// release allocated memory from BigBuff.
|
// release allocated memory from BigBuff.
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
StartTicks();
|
StartTicks();
|
||||||
|
|
||||||
DbpString("Hitag2 sniffing end, use `lf hitag list` for annotations");
|
DbpString("Hitag2 sniffing end, use `lf hitag list` for annotations");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
|
void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
|
|
||||||
StopTicks();
|
StopTicks();
|
||||||
|
|
||||||
int frame_count = 0, response = 0, overflow = 0;
|
int frame_count = 0, response = 0, overflow = 0;
|
||||||
uint8_t rx[HITAG_FRAME_LEN];
|
uint8_t rx[HITAG_FRAME_LEN];
|
||||||
size_t rxlen = 0;
|
size_t rxlen = 0;
|
||||||
|
@ -910,7 +910,7 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
memset(rx, 0x00, sizeof(rx));
|
memset(rx, 0x00, sizeof(rx));
|
||||||
|
|
||||||
DbpString("Starting Hitag2 simulation");
|
DbpString("Starting Hitag2 simulation");
|
||||||
|
|
||||||
LED_D_ON();
|
LED_D_ON();
|
||||||
hitag2_init();
|
hitag2_init();
|
||||||
|
|
||||||
|
@ -927,7 +927,7 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
}
|
}
|
||||||
Dbprintf("| %d | %08x |", i, block);
|
Dbprintf("| %d | %08x |", i, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up simulator mode, frequency divisor which will drive the FPGA
|
// Set up simulator mode, frequency divisor which will drive the FPGA
|
||||||
// and analog mux selection.
|
// and analog mux selection.
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT);
|
||||||
|
@ -941,9 +941,9 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
// Disable modulation at default, which means release resistance
|
// Disable modulation at default, which means release resistance
|
||||||
LOW(GPIO_SSC_DOUT);
|
LOW(GPIO_SSC_DOUT);
|
||||||
|
|
||||||
// Enable Peripheral Clock for
|
// Enable Peripheral Clock for
|
||||||
// TIMER_CLOCK0, used to measure exact timing before answering
|
// TIMER_CLOCK0, used to measure exact timing before answering
|
||||||
// TIMER_CLOCK1, used to capture edges of the tag frames
|
// TIMER_CLOCK1, used to capture edges of the tag frames
|
||||||
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1);
|
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1);
|
||||||
|
|
||||||
AT91C_BASE_PIOA->PIO_BSR = GPIO_SSC_FRAME;
|
AT91C_BASE_PIOA->PIO_BSR = GPIO_SSC_FRAME;
|
||||||
|
@ -953,8 +953,8 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
|
|
||||||
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
|
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
|
||||||
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
|
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
|
||||||
|
|
||||||
// TC1: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
|
// TC1: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
|
||||||
// external trigger rising edge, load RA on rising edge of TIOA.
|
// external trigger rising edge, load RA on rising edge of TIOA.
|
||||||
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK | AT91C_TC_ETRGEDG_RISING | AT91C_TC_ABETRG | AT91C_TC_LDRA_RISING;
|
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK | AT91C_TC_ETRGEDG_RISING | AT91C_TC_ABETRG | AT91C_TC_LDRA_RISING;
|
||||||
|
@ -962,7 +962,7 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
// Enable and reset counter
|
// Enable and reset counter
|
||||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||||
|
|
||||||
// synchronized startup procedure
|
// synchronized startup procedure
|
||||||
while (AT91C_BASE_TC1->TC_CV > 0); // wait until TC0 returned to zero
|
while (AT91C_BASE_TC1->TC_CV > 0); // wait until TC0 returned to zero
|
||||||
|
|
||||||
|
@ -1008,7 +1008,7 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
if (rxlen > 4) {
|
if (rxlen > 4) {
|
||||||
frame_count++;
|
frame_count++;
|
||||||
LogTrace(rx, nbytes(rxlen), response, response, NULL, true);
|
LogTrace(rx, nbytes(rxlen), response, response, NULL, true);
|
||||||
|
|
||||||
// Disable timer 1 with external trigger to avoid triggers during our own modulation
|
// Disable timer 1 with external trigger to avoid triggers during our own modulation
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
|
|
||||||
|
@ -1025,7 +1025,7 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
// Send and store the tag answer (if there is any)
|
// Send and store the tag answer (if there is any)
|
||||||
if (txlen) {
|
if (txlen) {
|
||||||
hitag_send_frame(tx, txlen);
|
hitag_send_frame(tx, txlen);
|
||||||
LogTrace(tx, nbytes(txlen), 0, 0, NULL, false);
|
LogTrace(tx, nbytes(txlen), 0, 0, NULL, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the received frame and response timing info
|
// Reset the received frame and response timing info
|
||||||
|
@ -1049,12 +1049,12 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
set_tracing(false);
|
set_tracing(false);
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
|
|
||||||
// release allocated memory from BigBuff.
|
// release allocated memory from BigBuff.
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
|
|
||||||
StartTicks();
|
StartTicks();
|
||||||
|
|
||||||
DbpString("Sim Stopped");
|
DbpString("Sim Stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1133,12 +1133,12 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) {
|
||||||
LED_D_ON();
|
LED_D_ON();
|
||||||
hitag2_init();
|
hitag2_init();
|
||||||
|
|
||||||
|
|
||||||
// Set fpga in edge detect with reader field, we can modulate as reader now
|
// Set fpga in edge detect with reader field, we can modulate as reader now
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_READER_FIELD);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_READER_FIELD);
|
||||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
|
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
|
||||||
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
||||||
|
|
||||||
// Configure output and enable pin that is connected to the FPGA (for modulating)
|
// Configure output and enable pin that is connected to the FPGA (for modulating)
|
||||||
AT91C_BASE_PIOA->PIO_OER |= GPIO_SSC_DOUT;
|
AT91C_BASE_PIOA->PIO_OER |= GPIO_SSC_DOUT;
|
||||||
AT91C_BASE_PIOA->PIO_PER |= GPIO_SSC_DOUT;
|
AT91C_BASE_PIOA->PIO_PER |= GPIO_SSC_DOUT;
|
||||||
|
@ -1146,11 +1146,11 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) {
|
||||||
// Disable modulation at default, which means enable the field
|
// Disable modulation at default, which means enable the field
|
||||||
LOW(GPIO_SSC_DOUT);
|
LOW(GPIO_SSC_DOUT);
|
||||||
|
|
||||||
// Enable Peripheral Clock for
|
// Enable Peripheral Clock for
|
||||||
// TIMER_CLOCK0, used to measure exact timing before answering
|
// TIMER_CLOCK0, used to measure exact timing before answering
|
||||||
// TIMER_CLOCK1, used to capture edges of the tag frames
|
// TIMER_CLOCK1, used to capture edges of the tag frames
|
||||||
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1);
|
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1);
|
||||||
|
|
||||||
// PIO_A - BSR
|
// PIO_A - BSR
|
||||||
AT91C_BASE_PIOA->PIO_BSR = GPIO_SSC_FRAME;
|
AT91C_BASE_PIOA->PIO_BSR = GPIO_SSC_FRAME;
|
||||||
|
|
||||||
|
@ -1159,8 +1159,8 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) {
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
|
|
||||||
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
|
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
|
||||||
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
|
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
|
||||||
|
|
||||||
// TC1: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
|
// TC1: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
|
||||||
// external trigger rising edge, load RA on falling edge of TIOA.
|
// external trigger rising edge, load RA on falling edge of TIOA.
|
||||||
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK | AT91C_TC_ETRGEDG_FALLING | AT91C_TC_ABETRG | AT91C_TC_LDRA_FALLING;
|
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK | AT91C_TC_ETRGEDG_FALLING | AT91C_TC_ABETRG | AT91C_TC_LDRA_FALLING;
|
||||||
|
@ -1328,14 +1328,14 @@ out:
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
set_tracing(false);
|
set_tracing(false);
|
||||||
|
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
|
|
||||||
// release allocated memory from BigBuff.
|
// release allocated memory from BigBuff.
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
StartTicks();
|
StartTicks();
|
||||||
|
|
||||||
if (bSuccessful)
|
if (bSuccessful)
|
||||||
cmd_send(CMD_ACK, bSuccessful, 0, 0, (uint8_t *)tag.sectors, 48);
|
cmd_send(CMD_ACK, bSuccessful, 0, 0, (uint8_t *)tag.sectors, 48);
|
||||||
else
|
else
|
||||||
|
@ -1343,9 +1343,9 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
|
void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
|
||||||
|
|
||||||
StopTicks();
|
StopTicks();
|
||||||
|
|
||||||
int frame_count = 0, response = 0;
|
int frame_count = 0, response = 0;
|
||||||
uint8_t rx[HITAG_FRAME_LEN];
|
uint8_t rx[HITAG_FRAME_LEN];
|
||||||
size_t rxlen = 0;
|
size_t rxlen = 0;
|
||||||
|
@ -1381,7 +1381,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
|
||||||
break;
|
break;
|
||||||
default: {
|
default: {
|
||||||
Dbprintf("Error, unknown function: %d", htf);
|
Dbprintf("Error, unknown function: %d", htf);
|
||||||
StartTicks();
|
StartTicks();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1402,7 +1402,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
|
||||||
// Disable modulation at default, which means enable the field
|
// Disable modulation at default, which means enable the field
|
||||||
LOW(GPIO_SSC_DOUT);
|
LOW(GPIO_SSC_DOUT);
|
||||||
|
|
||||||
// Enable Peripheral Clock for
|
// Enable Peripheral Clock for
|
||||||
// TIMER_CLOCK0, used to measure exact timing before answering
|
// TIMER_CLOCK0, used to measure exact timing before answering
|
||||||
// TIMER_CLOCK1, used to capture edges of the tag frames
|
// TIMER_CLOCK1, used to capture edges of the tag frames
|
||||||
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1);
|
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1);
|
||||||
|
@ -1414,11 +1414,11 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
|
|
||||||
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
|
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
|
||||||
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
|
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
|
||||||
|
|
||||||
// TC1: Capture mode, defaul timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
|
// TC1: Capture mode, defaul timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
|
||||||
// external trigger rising edge, load RA on falling edge of TIOA.
|
// external trigger rising edge, load RA on falling edge of TIOA.
|
||||||
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK
|
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK
|
||||||
| AT91C_TC_ETRGEDG_FALLING
|
| AT91C_TC_ETRGEDG_FALLING
|
||||||
| AT91C_TC_ABETRG
|
| AT91C_TC_ABETRG
|
||||||
| AT91C_TC_LDRA_FALLING;
|
| AT91C_TC_LDRA_FALLING;
|
||||||
|
@ -1428,7 +1428,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||||
|
|
||||||
while (AT91C_BASE_TC0->TC_CV > 0) {};
|
while (AT91C_BASE_TC0->TC_CV > 0) {};
|
||||||
|
|
||||||
// Reset the received frame, frame count and timing info
|
// Reset the received frame, frame count and timing info
|
||||||
lastbit = 1;
|
lastbit = 1;
|
||||||
bStop = false;
|
bStop = false;
|
||||||
|
@ -1450,7 +1450,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
|
||||||
Dbprintf("Error, unknown hitag reader type: %d", htf);
|
Dbprintf("Error, unknown hitag reader type: %d", htf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!bStop && !BUTTON_PRESS() && !usb_poll_validate_length()) {
|
while (!bStop && !BUTTON_PRESS() && !usb_poll_validate_length()) {
|
||||||
|
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
|
@ -1458,7 +1458,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
|
||||||
// Check if frame was captured and store it
|
// Check if frame was captured and store it
|
||||||
if (rxlen > 0) {
|
if (rxlen > 0) {
|
||||||
frame_count++;
|
frame_count++;
|
||||||
LogTrace(rx, nbytes(rxlen), response, response, NULL, false);
|
LogTrace(rx, nbytes(rxlen), response, response, NULL, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// By default reset the transmission buffer
|
// By default reset the transmission buffer
|
||||||
|
@ -1495,7 +1495,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
|
||||||
// Add transmitted frame to total count
|
// Add transmitted frame to total count
|
||||||
if (txlen > 0) {
|
if (txlen > 0) {
|
||||||
frame_count++;
|
frame_count++;
|
||||||
LogTrace(tx, nbytes(txlen), HITAG_T_WAIT_2, HITAG_T_WAIT_2, NULL, true);
|
LogTrace(tx, nbytes(txlen), HITAG_T_WAIT_2, HITAG_T_WAIT_2, NULL, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset values for receiving frames
|
// Reset values for receiving frames
|
||||||
|
@ -1577,7 +1577,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
|
||||||
}
|
}
|
||||||
// if we saw over 100 wierd values break it probably isn't hitag...
|
// if we saw over 100 wierd values break it probably isn't hitag...
|
||||||
if (errorCount > 100) break;
|
if (errorCount > 100) break;
|
||||||
|
|
||||||
// We can break this loop if we received the last bit from a frame
|
// We can break this loop if we received the last bit from a frame
|
||||||
if (AT91C_BASE_TC1->TC_CV > T0 * HITAG_T_EOF) {
|
if (AT91C_BASE_TC1->TC_CV > T0 * HITAG_T_EOF) {
|
||||||
if (rxlen > 0) break;
|
if (rxlen > 0) break;
|
||||||
|
@ -1594,11 +1594,11 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
set_tracing(false);
|
set_tracing(false);
|
||||||
|
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
|
|
||||||
StartTicks();
|
StartTicks();
|
||||||
|
|
||||||
cmd_send(CMD_ACK, bSuccessful, 0, 0, (uint8_t *)tag.sectors, 48);
|
cmd_send(CMD_ACK, bSuccessful, 0, 0, (uint8_t *)tag.sectors, 48);
|
||||||
}
|
}
|
||||||
|
|
224
armsrc/hitagS.c
224
armsrc/hitagS.c
|
@ -49,7 +49,7 @@ bool end = false;
|
||||||
// T0 = TIMER_CLOCK1 / 125000 = 192
|
// T0 = TIMER_CLOCK1 / 125000 = 192
|
||||||
#ifndef T0
|
#ifndef T0
|
||||||
#define T0 192
|
#define T0 192
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define HITAG_FRAME_LEN 20
|
#define HITAG_FRAME_LEN 20
|
||||||
#define HITAG_T_STOP 36 /* T_EOF should be > 36 */
|
#define HITAG_T_STOP 36 /* T_EOF should be > 36 */
|
||||||
|
@ -255,7 +255,7 @@ static void hitag_reader_send_frame(const uint8_t *frame, size_t frame_len) {
|
||||||
// Send the content of the frame
|
// Send the content of the frame
|
||||||
for (size_t i = 0; i < frame_len; i++) {
|
for (size_t i = 0; i < frame_len; i++) {
|
||||||
// if (frame[0] == 0xf8) {
|
// if (frame[0] == 0xf8) {
|
||||||
//Dbprintf("BIT: %d",(frame[i / 8] >> (7 - (i % 8))) & 1);
|
//Dbprintf("BIT: %d",(frame[i / 8] >> (7 - (i % 8))) & 1);
|
||||||
// }
|
// }
|
||||||
hitag_reader_send_bit((frame[i / 8] >> (7 - (i % 8))) & 1);
|
hitag_reader_send_bit((frame[i / 8] >> (7 - (i % 8))) & 1);
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ static void hitag_reader_send_frame(const uint8_t *frame, size_t frame_len) {
|
||||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
|
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
|
||||||
|
|
||||||
HIGH(GPIO_SSC_DOUT);
|
HIGH(GPIO_SSC_DOUT);
|
||||||
|
|
||||||
// Wait for 4-10 times the carrier period
|
// Wait for 4-10 times the carrier period
|
||||||
while (AT91C_BASE_TC0->TC_CV < T0 * 6) {};
|
while (AT91C_BASE_TC0->TC_CV < T0 * 6) {};
|
||||||
|
|
||||||
|
@ -285,7 +285,7 @@ static int check_select(uint8_t *rx, uint32_t uid) {
|
||||||
temp_uid = ans;
|
temp_uid = ans;
|
||||||
if (ans == tag.uid)
|
if (ans == tag.uid)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,12 +376,12 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||||
temp2++;
|
temp2++;
|
||||||
*txlen = 32;
|
*txlen = 32;
|
||||||
state = _hitag2_init(REV64(tag.key),
|
state = _hitag2_init(REV64(tag.key),
|
||||||
REV32(tag.pages[0][0]),
|
REV32(tag.pages[0][0]),
|
||||||
REV32(((rx[3] << 24) + (rx[2] << 16) + (rx[1] << 8) + rx[0]))
|
REV32(((rx[3] << 24) + (rx[2] << 16) + (rx[1] << 8) + rx[0]))
|
||||||
);
|
);
|
||||||
Dbprintf(",{0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X}",
|
Dbprintf(",{0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X}",
|
||||||
rx[0], rx[1], rx[2], rx[3], rx[4], rx[5], rx[6], rx[7]);
|
rx[0], rx[1], rx[2], rx[3], rx[4], rx[5], rx[6], rx[7]);
|
||||||
|
|
||||||
switch (tag.mode) {
|
switch (tag.mode) {
|
||||||
case HT_STANDARD:
|
case HT_STANDARD:
|
||||||
sof_bits = 1;
|
sof_bits = 1;
|
||||||
|
@ -401,7 +401,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||||
|
|
||||||
for (i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++)
|
||||||
_hitag2_byte(&state);
|
_hitag2_byte(&state);
|
||||||
|
|
||||||
//send con2, pwdh0, pwdl0, pwdl1 encrypted as a response
|
//send con2, pwdh0, pwdl0, pwdl1 encrypted as a response
|
||||||
tx[0] = _hitag2_byte(&state) ^ ((tag.pages[0][1] >> 16) & 0xff);
|
tx[0] = _hitag2_byte(&state) ^ ((tag.pages[0][1] >> 16) & 0xff);
|
||||||
tx[1] = _hitag2_byte(&state) ^ tag.pwdh0;
|
tx[1] = _hitag2_byte(&state) ^ tag.pwdh0;
|
||||||
|
@ -681,44 +681,44 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
uid1 = (uid[0] << 7)
|
uid1 = (uid[0] << 7)
|
||||||
| (uid[1] << 6)
|
| (uid[1] << 6)
|
||||||
| (uid[2] << 5)
|
| (uid[2] << 5)
|
||||||
| (uid[3] << 4)
|
| (uid[3] << 4)
|
||||||
| (uid[4] << 3)
|
| (uid[4] << 3)
|
||||||
| (uid[5] << 2)
|
| (uid[5] << 2)
|
||||||
| (uid[6] << 1)
|
| (uid[6] << 1)
|
||||||
| uid[7];
|
| uid[7];
|
||||||
|
|
||||||
uid2 = (uid[8] << 7)
|
uid2 = (uid[8] << 7)
|
||||||
| (uid[9] << 6)
|
| (uid[9] << 6)
|
||||||
| (uid[10] << 5)
|
| (uid[10] << 5)
|
||||||
| (uid[11] << 4)
|
| (uid[11] << 4)
|
||||||
| (uid[12] << 3)
|
| (uid[12] << 3)
|
||||||
| (uid[13] << 2)
|
| (uid[13] << 2)
|
||||||
| (uid[14] << 1)
|
| (uid[14] << 1)
|
||||||
| uid[15];
|
| uid[15];
|
||||||
|
|
||||||
uid3 = (uid[16] << 7)
|
uid3 = (uid[16] << 7)
|
||||||
| (uid[17] << 6)
|
| (uid[17] << 6)
|
||||||
| (uid[18] << 5)
|
| (uid[18] << 5)
|
||||||
| (uid[19] << 4)
|
| (uid[19] << 4)
|
||||||
| (uid[20] << 3)
|
| (uid[20] << 3)
|
||||||
| (uid[21] << 2)
|
| (uid[21] << 2)
|
||||||
| (uid[22] << 1)
|
| (uid[22] << 1)
|
||||||
| uid[23];
|
| uid[23];
|
||||||
|
|
||||||
uid4 = (uid[24] << 7)
|
uid4 = (uid[24] << 7)
|
||||||
| (uid[25] << 6)
|
| (uid[25] << 6)
|
||||||
| (uid[26] << 5)
|
| (uid[26] << 5)
|
||||||
| (uid[27] << 4)
|
| (uid[27] << 4)
|
||||||
| (uid[28] << 3)
|
| (uid[28] << 3)
|
||||||
| (uid[29] << 2)
|
| (uid[29] << 2)
|
||||||
| (uid[30] << 1)
|
| (uid[30] << 1)
|
||||||
| uid[31];
|
| uid[31];
|
||||||
|
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
Dbprintf("UID: %02X %02X %02X %02X", uid1, uid2, uid3, uid4);
|
Dbprintf("UID: %02X %02X %02X %02X", uid1, uid2, uid3, uid4);
|
||||||
|
|
||||||
tag.uid = (uid4 << 24 | uid3 << 16 | uid2 << 8 | uid1);
|
tag.uid = (uid4 << 24 | uid3 << 16 | uid2 << 8 | uid1);
|
||||||
|
|
||||||
//select uid
|
//select uid
|
||||||
|
@ -729,40 +729,40 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||||
calc_crc(&crc, uid2, 8);
|
calc_crc(&crc, uid2, 8);
|
||||||
calc_crc(&crc, uid3, 8);
|
calc_crc(&crc, uid3, 8);
|
||||||
calc_crc(&crc, uid4, 8);
|
calc_crc(&crc, uid4, 8);
|
||||||
|
|
||||||
for (i = 0; i < 100; i++) {
|
for (i = 0; i < 100; i++) {
|
||||||
response_bit[i] = 0;
|
response_bit[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
response_bit[i] = 0;
|
response_bit[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 5; i < 37; i++) {
|
for (i = 5; i < 37; i++) {
|
||||||
response_bit[i] = uid[i - 5];
|
response_bit[i] = uid[i - 5];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; j < 8; j++) {
|
for (j = 0; j < 8; j++) {
|
||||||
response_bit[i] = 0;
|
response_bit[i] = 0;
|
||||||
if ((crc & ((mask << 7) >> j)) != 0)
|
if ((crc & ((mask << 7) >> j)) != 0)
|
||||||
response_bit[i] = 1;
|
response_bit[i] = 1;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
k = 0;
|
k = 0;
|
||||||
for (i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
tx[i] = (response_bit[k] << 7)
|
tx[i] = (response_bit[k] << 7)
|
||||||
| (response_bit[k + 1] << 6)
|
| (response_bit[k + 1] << 6)
|
||||||
| (response_bit[k + 2] << 5)
|
| (response_bit[k + 2] << 5)
|
||||||
| (response_bit[k + 3] << 4)
|
| (response_bit[k + 3] << 4)
|
||||||
| (response_bit[k + 4] << 3)
|
| (response_bit[k + 4] << 3)
|
||||||
| (response_bit[k + 5] << 2)
|
| (response_bit[k + 5] << 2)
|
||||||
| (response_bit[k + 6] << 1)
|
| (response_bit[k + 6] << 1)
|
||||||
| response_bit[k + 7];
|
| response_bit[k + 7];
|
||||||
|
|
||||||
k += 8;
|
k += 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
tag.pstate = HT_INIT;
|
tag.pstate = HT_INIT;
|
||||||
} else if (tag.pstate == HT_INIT && rxlen == 44) {
|
} else if (tag.pstate == HT_INIT && rxlen == 44) {
|
||||||
// received configuration after select command
|
// received configuration after select command
|
||||||
|
@ -811,7 +811,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||||
|
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
Dbprintf("conf0: %02X conf1: %02X conf2: %02X", conf_pages[0], conf_pages[1], conf_pages[2]);
|
Dbprintf("conf0: %02X conf1: %02X conf2: %02X", conf_pages[0], conf_pages[1], conf_pages[2]);
|
||||||
|
|
||||||
if (tag.auth == 1) {
|
if (tag.auth == 1) {
|
||||||
//if the tag is in authentication mode try the key or challenge
|
//if the tag is in authentication mode try the key or challenge
|
||||||
*txlen = 64;
|
*txlen = 64;
|
||||||
|
@ -871,7 +871,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||||
state = _hitag2_init(REV64(key), REV32(tag.uid), REV32(rnd));
|
state = _hitag2_init(REV64(key), REV32(tag.uid), REV32(rnd));
|
||||||
for (i = 0; i < 5; i++)
|
for (i = 0; i < 5; i++)
|
||||||
_hitag2_byte(&state);
|
_hitag2_byte(&state);
|
||||||
|
|
||||||
pwdh0 = ((rx[1] & 0x0f) * 16 + ((rx[2] & 0xf0) / 16)) ^ _hitag2_byte(&state);
|
pwdh0 = ((rx[1] & 0x0f) * 16 + ((rx[2] & 0xf0) / 16)) ^ _hitag2_byte(&state);
|
||||||
pwdl0 = ((rx[2] & 0x0f) * 16 + ((rx[3] & 0xf0) / 16)) ^ _hitag2_byte(&state);
|
pwdl0 = ((rx[2] & 0x0f) * 16 + ((rx[3] & 0xf0) / 16)) ^ _hitag2_byte(&state);
|
||||||
pwdl1 = ((rx[3] & 0x0f) * 16 + ((rx[4] & 0xf0) / 16)) ^ _hitag2_byte(&state);
|
pwdl1 = ((rx[3] & 0x0f) * 16 + ((rx[4] & 0xf0) / 16)) ^ _hitag2_byte(&state);
|
||||||
|
@ -893,9 +893,9 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||||
* Emulates a Hitag S Tag with the given data from the .hts file
|
* Emulates a Hitag S Tag with the given data from the .hts file
|
||||||
*/
|
*/
|
||||||
void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
|
void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
|
|
||||||
StopTicks();
|
StopTicks();
|
||||||
|
|
||||||
int frame_count = 0, response = 0, overflow = 0;
|
int frame_count = 0, response = 0, overflow = 0;
|
||||||
int i, j;
|
int i, j;
|
||||||
uint8_t rx[HITAG_FRAME_LEN];
|
uint8_t rx[HITAG_FRAME_LEN];
|
||||||
|
@ -907,7 +907,7 @@ void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
|
|
||||||
// Reset the received frame, frame count and timing info
|
// Reset the received frame, frame count and timing info
|
||||||
memset(rx, 0x00, sizeof(rx));
|
memset(rx, 0x00, sizeof(rx));
|
||||||
|
|
||||||
// free eventually allocated BigBuf memory
|
// free eventually allocated BigBuf memory
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
|
@ -931,7 +931,7 @@ void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
DbpString("Loading hitagS memory...");
|
DbpString("Loading hitagS memory...");
|
||||||
memcpy((uint8_t *)tag.pages, data, 4 * 64);
|
memcpy((uint8_t *)tag.pages, data, 4 * 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
tag.uid = (uint32_t)tag.pages[0];
|
tag.uid = (uint32_t)tag.pages[0];
|
||||||
tag.key = (intptr_t)tag.pages[3];
|
tag.key = (intptr_t)tag.pages[3];
|
||||||
tag.key <<= 16;
|
tag.key <<= 16;
|
||||||
|
@ -996,11 +996,11 @@ void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
// Disable modulation at default, which means release resistance
|
// Disable modulation at default, which means release resistance
|
||||||
LOW(GPIO_SSC_DOUT);
|
LOW(GPIO_SSC_DOUT);
|
||||||
|
|
||||||
// Enable Peripheral Clock for
|
// Enable Peripheral Clock for
|
||||||
// TIMER_CLOCK0, used to measure exact timing before answering
|
// TIMER_CLOCK0, used to measure exact timing before answering
|
||||||
// TIMER_CLOCK1, used to capture edges of the tag frames
|
// TIMER_CLOCK1, used to capture edges of the tag frames
|
||||||
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1);
|
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1);
|
||||||
|
|
||||||
AT91C_BASE_PIOA->PIO_BSR = GPIO_SSC_FRAME;
|
AT91C_BASE_PIOA->PIO_BSR = GPIO_SSC_FRAME;
|
||||||
|
|
||||||
// Disable timer during configuration
|
// Disable timer during configuration
|
||||||
|
@ -1008,20 +1008,20 @@ void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
|
|
||||||
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
|
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
|
||||||
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
|
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
|
||||||
|
|
||||||
// TC1: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
|
// TC1: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
|
||||||
// external trigger rising edge, load RA on rising edge of TIOA.
|
// external trigger rising edge, load RA on rising edge of TIOA.
|
||||||
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK
|
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK
|
||||||
| AT91C_TC_ETRGEDG_RISING | AT91C_TC_ABETRG | AT91C_TC_LDRA_RISING;
|
| AT91C_TC_ETRGEDG_RISING | AT91C_TC_ABETRG | AT91C_TC_LDRA_RISING;
|
||||||
|
|
||||||
// Enable and reset counter
|
// Enable and reset counter
|
||||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||||
|
|
||||||
// synchronized startup procedure
|
// synchronized startup procedure
|
||||||
while (AT91C_BASE_TC0->TC_CV > 0); // wait until TC0 returned to zero
|
while (AT91C_BASE_TC0->TC_CV > 0); // wait until TC0 returned to zero
|
||||||
|
|
||||||
while (!BUTTON_PRESS() && !usb_poll_validate_length()) {
|
while (!BUTTON_PRESS() && !usb_poll_validate_length()) {
|
||||||
|
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
|
@ -1100,7 +1100,7 @@ void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
// Reset the timer to restart while-loop that receives frames
|
// Reset the timer to restart while-loop that receives frames
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_SWTRG;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_SWTRG;
|
||||||
}
|
}
|
||||||
|
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
set_tracing(false);
|
set_tracing(false);
|
||||||
|
@ -1109,10 +1109,10 @@ void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
|
|
||||||
// release allocated memory from BigBuff.
|
// release allocated memory from BigBuff.
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
|
|
||||||
StartTicks();
|
StartTicks();
|
||||||
|
|
||||||
DbpString("Sim Stopped");
|
DbpString("Sim Stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1123,7 +1123,7 @@ void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
void ReadHitagS(hitag_function htf, hitag_data *htd) {
|
void ReadHitagS(hitag_function htf, hitag_data *htd) {
|
||||||
|
|
||||||
StopTicks();
|
StopTicks();
|
||||||
|
|
||||||
int i, j, z, k;
|
int i, j, z, k;
|
||||||
int frame_count = 0, response = 0;
|
int frame_count = 0, response = 0;
|
||||||
int response_bit[200];
|
int response_bit[200];
|
||||||
|
@ -1149,7 +1149,7 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
|
||||||
uint64_t key = 0;
|
uint64_t key = 0;
|
||||||
uint64_t NrAr = 0;
|
uint64_t NrAr = 0;
|
||||||
uint8_t key_[6];
|
uint8_t key_[6];
|
||||||
|
|
||||||
switch (htf) {
|
switch (htf) {
|
||||||
case RHTSF_CHALLENGE: {
|
case RHTSF_CHALLENGE: {
|
||||||
DbpString("Authenticating using nr,ar pair:");
|
DbpString("Authenticating using nr,ar pair:");
|
||||||
|
@ -1157,7 +1157,7 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
|
||||||
Dbhexdump(8, NrAr_, false);
|
Dbhexdump(8, NrAr_, false);
|
||||||
NrAr = NrAr_[7] | ((uint64_t)NrAr_[6]) << 8 | ((uint64_t)NrAr_[5]) << 16 | ((uint64_t)NrAr_[4]) << 24 | ((uint64_t)NrAr_[3]) << 32 |
|
NrAr = NrAr_[7] | ((uint64_t)NrAr_[6]) << 8 | ((uint64_t)NrAr_[5]) << 16 | ((uint64_t)NrAr_[4]) << 24 | ((uint64_t)NrAr_[3]) << 32 |
|
||||||
((uint64_t)NrAr_[2]) << 40 | ((uint64_t)NrAr_[1]) << 48 | ((uint64_t)NrAr_[0]) << 56;
|
((uint64_t)NrAr_[2]) << 40 | ((uint64_t)NrAr_[1]) << 48 | ((uint64_t)NrAr_[0]) << 56;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RHTSF_KEY: {
|
case RHTSF_KEY: {
|
||||||
DbpString("Authenticating using key:");
|
DbpString("Authenticating using key:");
|
||||||
|
@ -1188,17 +1188,17 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_READER_FIELD);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_READER_FIELD);
|
||||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
|
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
|
||||||
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
||||||
|
|
||||||
// Configure output and enable pin that is connected to the FPGA (for modulating)
|
// Configure output and enable pin that is connected to the FPGA (for modulating)
|
||||||
AT91C_BASE_PIOA->PIO_OER |= GPIO_SSC_DOUT;
|
AT91C_BASE_PIOA->PIO_OER |= GPIO_SSC_DOUT;
|
||||||
AT91C_BASE_PIOA->PIO_PER |= GPIO_SSC_DOUT;
|
AT91C_BASE_PIOA->PIO_PER |= GPIO_SSC_DOUT;
|
||||||
|
|
||||||
// Disable modulation at default, which means enable the field
|
// Disable modulation at default, which means enable the field
|
||||||
LOW(GPIO_SSC_DOUT);
|
LOW(GPIO_SSC_DOUT);
|
||||||
|
|
||||||
// Enable Peripheral Clock for
|
// Enable Peripheral Clock for
|
||||||
// TIMER_CLOCK0, used to measure exact timing before answering
|
// TIMER_CLOCK0, used to measure exact timing before answering
|
||||||
// TIMER_CLOCK1, used to capture edges of the tag frames
|
// TIMER_CLOCK1, used to capture edges of the tag frames
|
||||||
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1);
|
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1);
|
||||||
|
|
||||||
AT91C_BASE_PIOA->PIO_BSR = GPIO_SSC_FRAME;
|
AT91C_BASE_PIOA->PIO_BSR = GPIO_SSC_FRAME;
|
||||||
|
@ -1208,8 +1208,8 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
|
|
||||||
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
|
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
|
||||||
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
|
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
|
||||||
|
|
||||||
// TC1: Capture mode, defaul timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
|
// TC1: Capture mode, defaul timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
|
||||||
// external trigger rising edge, load RA on falling edge of TIOA.
|
// external trigger rising edge, load RA on falling edge of TIOA.
|
||||||
AT91C_BASE_TC1->TC_CMR =
|
AT91C_BASE_TC1->TC_CMR =
|
||||||
|
@ -1224,7 +1224,7 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
|
||||||
|
|
||||||
// synchronized startup procedure
|
// synchronized startup procedure
|
||||||
while (AT91C_BASE_TC0->TC_CV > 0); // wait until TC0 returned to zero
|
while (AT91C_BASE_TC0->TC_CV > 0); // wait until TC0 returned to zero
|
||||||
|
|
||||||
// Reset the received frame, frame count and timing info
|
// Reset the received frame, frame count and timing info
|
||||||
t_wait = 200;
|
t_wait = 200;
|
||||||
|
|
||||||
|
@ -1252,7 +1252,7 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
|
||||||
if (hitagS_handle_tag_auth(htf, key, NrAr, rx, rxlen, tx, &txlen) == -1)
|
if (hitagS_handle_tag_auth(htf, key, NrAr, rx, rxlen, tx, &txlen) == -1)
|
||||||
bStop = !false;
|
bStop = !false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag.pstate == HT_SELECTED && tag.tstate == HT_NO_OP && rxlen > 0) {
|
if (tag.pstate == HT_SELECTED && tag.tstate == HT_NO_OP && rxlen > 0) {
|
||||||
//send read request
|
//send read request
|
||||||
tag.tstate = HT_READING_PAGE;
|
tag.tstate = HT_READING_PAGE;
|
||||||
|
@ -1263,9 +1263,9 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
|
||||||
calc_crc(&crc, 0x00 + ((sendNum % 16) * 16), 4);
|
calc_crc(&crc, 0x00 + ((sendNum % 16) * 16), 4);
|
||||||
tx[1] = 0x00 + ((sendNum % 16) * 16) + (crc / 16);
|
tx[1] = 0x00 + ((sendNum % 16) * 16) + (crc / 16);
|
||||||
tx[2] = 0x00 + (crc % 16) * 16;
|
tx[2] = 0x00 + (crc % 16) * 16;
|
||||||
} else if (tag.pstate == HT_SELECTED
|
} else if (tag.pstate == HT_SELECTED
|
||||||
&& tag.tstate == HT_READING_PAGE
|
&& tag.tstate == HT_READING_PAGE
|
||||||
&& rxlen > 0) {
|
&& rxlen > 0) {
|
||||||
//save received data
|
//save received data
|
||||||
z = 0;
|
z = 0;
|
||||||
for (i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
|
@ -1315,13 +1315,13 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
|
||||||
(uint8_t) key & 0xff,
|
(uint8_t) key & 0xff,
|
||||||
pwdl1,
|
pwdl1,
|
||||||
pwdl0
|
pwdl0
|
||||||
);
|
);
|
||||||
Dbprintf("Page[ 3]: %02X %02X %02X %02X",
|
Dbprintf("Page[ 3]: %02X %02X %02X %02X",
|
||||||
(uint8_t)(key >> 40) & 0xff,
|
(uint8_t)(key >> 40) & 0xff,
|
||||||
(uint8_t)(key >> 32) & 0xff,
|
(uint8_t)(key >> 32) & 0xff,
|
||||||
(uint8_t)(key >> 24) & 0xff,
|
(uint8_t)(key >> 24) & 0xff,
|
||||||
(uint8_t)(key >> 16) & 0xff
|
(uint8_t)(key >> 16) & 0xff
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
//if the authentication is done with a challenge the key and password are unknown
|
//if the authentication is done with a challenge the key and password are unknown
|
||||||
Dbprintf("Page[ 2]: __ __ __ __");
|
Dbprintf("Page[ 2]: __ __ __ __");
|
||||||
|
@ -1362,7 +1362,7 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
|
||||||
// Add transmitted frame to total count
|
// Add transmitted frame to total count
|
||||||
if (txlen > 0) {
|
if (txlen > 0) {
|
||||||
frame_count++;
|
frame_count++;
|
||||||
LogTrace(tx, nbytes(txlen), HITAG_T_WAIT_2, 0, NULL, true);
|
LogTrace(tx, nbytes(txlen), HITAG_T_WAIT_2, 0, NULL, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset values for receiving frames
|
// Reset values for receiving frames
|
||||||
|
@ -1437,13 +1437,13 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
set_tracing(false);
|
set_tracing(false);
|
||||||
|
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
|
|
||||||
StartTicks();
|
StartTicks();
|
||||||
|
|
||||||
cmd_send(CMD_ACK, bSuccessful, 0, 0, 0, 0);
|
cmd_send(CMD_ACK, bSuccessful, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1452,9 +1452,9 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
|
||||||
* Writes the given 32Bit data into page_
|
* Writes the given 32Bit data into page_
|
||||||
*/
|
*/
|
||||||
void WritePageHitagS(hitag_function htf, hitag_data *htd, int page_) {
|
void WritePageHitagS(hitag_function htf, hitag_data *htd, int page_) {
|
||||||
|
|
||||||
StopTicks();
|
StopTicks();
|
||||||
|
|
||||||
int frame_count = 0, response = 0;
|
int frame_count = 0, response = 0;
|
||||||
uint8_t rx[HITAG_FRAME_LEN];
|
uint8_t rx[HITAG_FRAME_LEN];
|
||||||
size_t rxlen = 0;
|
size_t rxlen = 0;
|
||||||
|
@ -1474,11 +1474,11 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page_) {
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||||
|
|
||||||
bSuccessful = false;
|
bSuccessful = false;
|
||||||
|
|
||||||
// Clean up trace and prepare it for storing frames
|
// Clean up trace and prepare it for storing frames
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
clear_trace();
|
clear_trace();
|
||||||
|
|
||||||
//read given key/challenge, the page and the data
|
//read given key/challenge, the page and the data
|
||||||
uint8_t NrAr_[8];
|
uint8_t NrAr_[8];
|
||||||
uint64_t key = 0;
|
uint64_t key = 0;
|
||||||
|
@ -1529,11 +1529,11 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page_) {
|
||||||
// Disable modulation at default, which means enable the field
|
// Disable modulation at default, which means enable the field
|
||||||
LOW(GPIO_SSC_DOUT);
|
LOW(GPIO_SSC_DOUT);
|
||||||
|
|
||||||
// Enable Peripheral Clock for
|
// Enable Peripheral Clock for
|
||||||
// TIMER_CLOCK0, used to measure exact timing before answering
|
// TIMER_CLOCK0, used to measure exact timing before answering
|
||||||
// TIMER_CLOCK1, used to capture edges of the tag frames
|
// TIMER_CLOCK1, used to capture edges of the tag frames
|
||||||
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1);
|
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1);
|
||||||
|
|
||||||
AT91C_BASE_PIOA->PIO_BSR = GPIO_SSC_FRAME;
|
AT91C_BASE_PIOA->PIO_BSR = GPIO_SSC_FRAME;
|
||||||
|
|
||||||
// Disable timer during configuration
|
// Disable timer during configuration
|
||||||
|
@ -1552,7 +1552,7 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page_) {
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||||
|
|
||||||
while (AT91C_BASE_TC0->TC_CV > 0);
|
while (AT91C_BASE_TC0->TC_CV > 0);
|
||||||
|
|
||||||
// Reset the received frame, frame count and timing info
|
// Reset the received frame, frame count and timing info
|
||||||
lastbit = 1;
|
lastbit = 1;
|
||||||
bStop = false;
|
bStop = false;
|
||||||
|
@ -1664,7 +1664,7 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page_) {
|
||||||
tag_sof = reset_sof;
|
tag_sof = reset_sof;
|
||||||
response = 0;
|
response = 0;
|
||||||
uint32_t errorCount = 0;
|
uint32_t errorCount = 0;
|
||||||
|
|
||||||
// Receive frame, watch for at most T0*EOF periods
|
// Receive frame, watch for at most T0*EOF periods
|
||||||
while (AT91C_BASE_TC1->TC_CV < T0 * HITAG_T_WAIT_MAX) {
|
while (AT91C_BASE_TC1->TC_CV < T0 * HITAG_T_WAIT_MAX) {
|
||||||
// Check if falling edge in tag modulation is detected
|
// Check if falling edge in tag modulation is detected
|
||||||
|
@ -1714,13 +1714,13 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page_) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Ignore wierd value, is to small to mean anything
|
// Ignore wierd value, is to small to mean anything
|
||||||
errorCount++;
|
errorCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we saw over 100 wierd values break it probably isn't hitag...
|
// if we saw over 100 wierd values break it probably isn't hitag...
|
||||||
if (errorCount > 100) break;
|
if (errorCount > 100) break;
|
||||||
|
|
||||||
// We can break this loop if we received the last bit from a frame
|
// We can break this loop if we received the last bit from a frame
|
||||||
if (AT91C_BASE_TC1->TC_CV > T0 * HITAG_T_EOF) {
|
if (AT91C_BASE_TC1->TC_CV > T0 * HITAG_T_EOF) {
|
||||||
if (rxlen > 0)
|
if (rxlen > 0)
|
||||||
|
@ -1732,12 +1732,12 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page_) {
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
set_tracing(false);
|
set_tracing(false);
|
||||||
|
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
|
|
||||||
StartTicks();
|
StartTicks();
|
||||||
|
|
||||||
cmd_send(CMD_ACK, bSuccessful, 0, 0, 0, 0);
|
cmd_send(CMD_ACK, bSuccessful, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1795,7 +1795,7 @@ void check_challenges(bool file_given, uint8_t *data) {
|
||||||
// Disable modulation at default, which means enable the field
|
// Disable modulation at default, which means enable the field
|
||||||
LOW(GPIO_SSC_DOUT);
|
LOW(GPIO_SSC_DOUT);
|
||||||
|
|
||||||
// Enable Peripheral Clock for
|
// Enable Peripheral Clock for
|
||||||
// TIMER_CLOCK0, used to measure exact timing before answering
|
// TIMER_CLOCK0, used to measure exact timing before answering
|
||||||
// TIMER_CLOCK1, used to capture edges of the tag frames
|
// TIMER_CLOCK1, used to capture edges of the tag frames
|
||||||
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1);
|
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1);
|
||||||
|
@ -1807,7 +1807,7 @@ void check_challenges(bool file_given, uint8_t *data) {
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
|
|
||||||
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
|
// TC0: Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), no triggers
|
||||||
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
|
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK;
|
||||||
|
|
||||||
// TC1: Capture mode, defaul timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
|
// TC1: Capture mode, defaul timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
|
||||||
// external trigger rising edge, load RA on falling edge of TIOA.
|
// external trigger rising edge, load RA on falling edge of TIOA.
|
||||||
|
@ -1821,7 +1821,7 @@ void check_challenges(bool file_given, uint8_t *data) {
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||||
|
|
||||||
while (AT91C_BASE_TC0->TC_CV > 0) {};
|
while (AT91C_BASE_TC0->TC_CV > 0) {};
|
||||||
|
|
||||||
// Reset the received frame, frame count and timing info
|
// Reset the received frame, frame count and timing info
|
||||||
lastbit = 1;
|
lastbit = 1;
|
||||||
bStop = false;
|
bStop = false;
|
||||||
|
@ -2044,9 +2044,9 @@ void check_challenges(bool file_given, uint8_t *data) {
|
||||||
|
|
||||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
||||||
|
|
||||||
StartTicks();
|
StartTicks();
|
||||||
|
|
||||||
cmd_send(CMD_ACK, bSuccessful, 0, 0, 0, 0);
|
cmd_send(CMD_ACK, bSuccessful, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1586,7 +1586,7 @@ void SendRawCommand14443B_Ex(UsbCommand *c) {
|
||||||
iso14443b_setup();
|
iso14443b_setup();
|
||||||
clear_trace();
|
clear_trace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((param & ISO14B_SET_TIMEOUT))
|
if ((param & ISO14B_SET_TIMEOUT))
|
||||||
iso14b_set_timeout(timeout);
|
iso14b_set_timeout(timeout);
|
||||||
|
|
||||||
|
|
|
@ -771,7 +771,7 @@ int AutoCorrelate(const int *in, int *out, size_t len, int window, bool SaveGrph
|
||||||
|
|
||||||
int foo = ABS(hi - hi_1);
|
int foo = ABS(hi - hi_1);
|
||||||
int bar = (int)((int)((hi + hi_1) / 2) * 0.04);
|
int bar = (int)((int)((hi + hi_1) / 2) * 0.04);
|
||||||
|
|
||||||
if (verbose && foo < bar) {
|
if (verbose && foo < bar) {
|
||||||
distance = idx_1 - idx;
|
distance = idx_1 - idx;
|
||||||
PrintAndLogEx(SUCCESS, "possible 4% visible correlation %4d samples", distance);
|
PrintAndLogEx(SUCCESS, "possible 4% visible correlation %4d samples", distance);
|
||||||
|
|
|
@ -198,7 +198,7 @@ int CmdHF14BCmdRaw(const char *Cmd) {
|
||||||
i += 3;
|
i += 3;
|
||||||
while (Cmd[i] != ' ' && Cmd[i] != '\0') { i++; }
|
while (Cmd[i] != ' ' && Cmd[i] != '\0') { i++; }
|
||||||
i -= 2;
|
i -= 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return usage_hf_14b_raw();
|
return usage_hf_14b_raw();
|
||||||
}
|
}
|
||||||
|
@ -223,7 +223,7 @@ int CmdHF14BCmdRaw(const char *Cmd) {
|
||||||
PrintAndLogEx(WARNING, "unknown parameter '%c'\n", param_getchar(Cmd, i));
|
PrintAndLogEx(WARNING, "unknown parameter '%c'\n", param_getchar(Cmd, i));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
#define MAX_TIMEOUT 40542464 // = (2^32-1) * (8*16) / 13560000Hz * 1000ms/s
|
#define MAX_TIMEOUT 40542464 // = (2^32-1) * (8*16) / 13560000Hz * 1000ms/s
|
||||||
flags |= ISO14B_SET_TIMEOUT;
|
flags |= ISO14B_SET_TIMEOUT;
|
||||||
|
|
|
@ -688,7 +688,7 @@ int CmdHF15Dump(const char *Cmd) {
|
||||||
PrintAndLogEx(WARNING, "No tag found.");
|
PrintAndLogEx(WARNING, "No tag found.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileNameLen < 1) {
|
if (fileNameLen < 1) {
|
||||||
|
|
||||||
PrintAndLogEx(INFO, "Using UID as filename");
|
PrintAndLogEx(INFO, "Using UID as filename");
|
||||||
|
|
|
@ -1376,7 +1376,7 @@ int CmdHFiClassCloneTag(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00};
|
uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00};
|
||||||
uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||||
|
|
||||||
|
@ -1404,12 +1404,12 @@ int CmdHFiClassCloneTag(const char *Cmd) {
|
||||||
PrintAndLogEx(NORMAL, " %02x%02x%02x%02x%02x%02x%02x%02x |", p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
|
PrintAndLogEx(NORMAL, " %02x%02x%02x%02x%02x%02x%02x%02x |", p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
|
||||||
PrintAndLogEx(NORMAL, " MAC |%02x%02x%02x%02x|\n", p[8], p[9], p[10], p[11]);
|
PrintAndLogEx(NORMAL, " MAC |%02x%02x%02x%02x|\n", p[8], p[9], p[10], p[11]);
|
||||||
}
|
}
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbCommand resp;
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&w);
|
SendCommand(&w);
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 4500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 4500)) {
|
||||||
PrintAndLogEx(WARNING, "command execute timeout");
|
PrintAndLogEx(WARNING, "command execute timeout");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -897,10 +897,10 @@ int CmdLFfind(const char *Cmd) {
|
||||||
|
|
||||||
if (EM4x50Read("", false)) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("EM4x50 ID") " found!"); return 1;}
|
if (EM4x50Read("", false)) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("EM4x50 ID") " found!"); return 1;}
|
||||||
|
|
||||||
if (CmdHIDDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("HID Prox ID") " found!"); goto out;}
|
if (CmdHIDDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("HID Prox ID") " found!"); goto out;}
|
||||||
if (CmdAWIDDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("AWID ID") " found!"); goto out;}
|
if (CmdAWIDDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("AWID ID") " found!"); goto out;}
|
||||||
if (CmdParadoxDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Paradox ID") " found!"); goto out;}
|
if (CmdParadoxDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Paradox ID") " found!"); goto out;}
|
||||||
|
|
||||||
if (CmdEM410xDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("EM410x ID") " found!"); goto out;}
|
if (CmdEM410xDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("EM410x ID") " found!"); goto out;}
|
||||||
if (CmdFdxDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("FDX-B ID") " found!"); goto out;}
|
if (CmdFdxDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("FDX-B ID") " found!"); goto out;}
|
||||||
if (CmdGuardDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Guardall G-Prox II ID") " found!"); goto out; }
|
if (CmdGuardDemod("")) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Guardall G-Prox II ID") " found!"); goto out; }
|
||||||
|
|
|
@ -65,13 +65,13 @@ int usage_hitag_info(void) {
|
||||||
int usage_hitag_dump(void) {
|
int usage_hitag_dump(void) {
|
||||||
PrintAndLogEx(NORMAL, "Usage: lf hitag dump [h] p <pwd> f <name>");
|
PrintAndLogEx(NORMAL, "Usage: lf hitag dump [h] p <pwd> f <name>");
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
PrintAndLogEx(NORMAL, "Options:");
|
||||||
PrintAndLogEx(NORMAL, " h This help");
|
PrintAndLogEx(NORMAL, " h This help");
|
||||||
// PrintAndLogEx(NORMAL, " p <pwd> password");
|
// PrintAndLogEx(NORMAL, " p <pwd> password");
|
||||||
// PrintAndLogEx(NORMAL, " f <name> data filename, if no <name> given, UID will be used as filename");
|
// PrintAndLogEx(NORMAL, " f <name> data filename, if no <name> given, UID will be used as filename");
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
PrintAndLogEx(NORMAL, "Examples:");
|
||||||
PrintAndLogEx(NORMAL, " lf hitag dump f mydump");
|
PrintAndLogEx(NORMAL, " lf hitag dump f mydump");
|
||||||
PrintAndLogEx(NORMAL, " lf hitag dump p 4D494B52 f mydump");
|
PrintAndLogEx(NORMAL, " lf hitag dump p 4D494B52 f mydump");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int usage_hitag_reader(void) {
|
int usage_hitag_reader(void) {
|
||||||
|
@ -106,7 +106,7 @@ int usage_hitag_writer(void) {
|
||||||
}
|
}
|
||||||
int usage_hitag_checkchallenges(void) {
|
int usage_hitag_checkchallenges(void) {
|
||||||
PrintAndLogEx(NORMAL, "Check challenges, load a file with save hitag crypto challenges and test them all.");
|
PrintAndLogEx(NORMAL, "Check challenges, load a file with save hitag crypto challenges and test them all.");
|
||||||
PrintAndLogEx(NORMAL, "The file should be 8 * 60 bytes long, the file extension defaults to " _YELLOW_("`.cc`") );
|
PrintAndLogEx(NORMAL, "The file should be 8 * 60 bytes long, the file extension defaults to " _YELLOW_("`.cc`"));
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(NORMAL, "Usage: lf hitag cc [h] f <filename w/o extension>");
|
PrintAndLogEx(NORMAL, "Usage: lf hitag cc [h] f <filename w/o extension>");
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
PrintAndLogEx(NORMAL, "Options:");
|
||||||
|
@ -117,8 +117,8 @@ int usage_hitag_checkchallenges(void) {
|
||||||
PrintAndLogEx(NORMAL, " lf hitag cc f lf-hitag-challenges");
|
PrintAndLogEx(NORMAL, " lf hitag cc f lf-hitag-challenges");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdLFHitagList(const char *Cmd) {
|
int CmdLFHitagList(const char *Cmd) {
|
||||||
CmdTraceList("hitag");
|
CmdTraceList("hitag");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ int CmdLFHitagSniff(const char *Cmd) {
|
||||||
|
|
||||||
char ctmp = tolower(param_getchar(Cmd, 0));
|
char ctmp = tolower(param_getchar(Cmd, 0));
|
||||||
if (ctmp == 'h') return usage_hitag_sniff();
|
if (ctmp == 'h') return usage_hitag_sniff();
|
||||||
|
|
||||||
UsbCommand c = {CMD_SNIFF_HITAG, {0, 0, 0}};
|
UsbCommand c = {CMD_SNIFF_HITAG, {0, 0, 0}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
@ -271,16 +271,16 @@ int CmdLFHitagSim(const char *Cmd) {
|
||||||
size_t datalen = 0;
|
size_t datalen = 0;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
char filename[FILE_PATH_SIZE] = { 0x00 };
|
char filename[FILE_PATH_SIZE] = { 0x00 };
|
||||||
|
|
||||||
UsbCommand c = {CMD_SIMULATE_HITAG, {0, 0, 0}};
|
UsbCommand c = {CMD_SIMULATE_HITAG, {0, 0, 0}};
|
||||||
|
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||||
case 'h':
|
case 'h':
|
||||||
free(data);
|
free(data);
|
||||||
return usage_hitag_sim();
|
return usage_hitag_sim();
|
||||||
case '2':
|
case '2':
|
||||||
maxdatalen = 48;
|
maxdatalen = 48;
|
||||||
cmdp++;
|
cmdp++;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
|
@ -288,36 +288,36 @@ int CmdLFHitagSim(const char *Cmd) {
|
||||||
maxdatalen = 4 * 64;
|
maxdatalen = 4 * 64;
|
||||||
cmdp++;
|
cmdp++;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
param_getstr(Cmd, cmdp+1, filename, sizeof(filename));
|
param_getstr(Cmd, cmdp + 1, filename, sizeof(filename));
|
||||||
res = loadFileEML(filename, "eml", data, &datalen);
|
res = loadFileEML(filename, "eml", data, &datalen);
|
||||||
if ( res > 0 || datalen != maxdatalen) {
|
if (res > 0 || datalen != maxdatalen) {
|
||||||
PrintAndLogDevice(FAILED, "error, bytes read mismatch file size");
|
PrintAndLogDevice(FAILED, "error, bytes read mismatch file size");
|
||||||
errors = true;
|
errors = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tag_mem_supplied = true;
|
tag_mem_supplied = true;
|
||||||
cmdp += 2;
|
cmdp += 2;
|
||||||
break;
|
break;
|
||||||
case 'j':
|
case 'j':
|
||||||
param_getstr(Cmd, cmdp+1, filename, sizeof(filename));
|
param_getstr(Cmd, cmdp + 1, filename, sizeof(filename));
|
||||||
res = loadFileJSON(filename, "json", data, maxdatalen, &datalen);
|
res = loadFileJSON(filename, "json", data, maxdatalen, &datalen);
|
||||||
if ( res > 0) {
|
if (res > 0) {
|
||||||
errors = true;
|
errors = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tag_mem_supplied = true;
|
tag_mem_supplied = true;
|
||||||
cmdp += 2;
|
cmdp += 2;
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
param_getstr(Cmd, cmdp+1, filename, sizeof(filename));
|
param_getstr(Cmd, cmdp + 1, filename, sizeof(filename));
|
||||||
res = loadFile(filename, "bin", data, maxdatalen, &datalen);
|
res = loadFile(filename, "bin", data, maxdatalen, &datalen);
|
||||||
if ( res > 0 ) {
|
if (res > 0) {
|
||||||
errors = true;
|
errors = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tag_mem_supplied = true;
|
tag_mem_supplied = true;
|
||||||
cmdp += 2;
|
cmdp += 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||||
|
@ -325,30 +325,30 @@ int CmdLFHitagSim(const char *Cmd) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Validations
|
//Validations
|
||||||
if (errors || cmdp == 0) {
|
if (errors || cmdp == 0) {
|
||||||
free(data);
|
free(data);
|
||||||
return usage_hitag_sim();
|
return usage_hitag_sim();
|
||||||
}
|
}
|
||||||
|
|
||||||
c.arg[0] = (uint32_t)tag_mem_supplied;
|
c.arg[0] = (uint32_t)tag_mem_supplied;
|
||||||
if ( tag_mem_supplied ) {
|
if (tag_mem_supplied) {
|
||||||
memcpy(c.d.asBytes, data, datalen);
|
memcpy(c.d.asBytes, data, datalen);
|
||||||
}
|
}
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
free(data);
|
free(data);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdLFHitagInfo(const char *Cmd) {
|
int CmdLFHitagInfo(const char *Cmd) {
|
||||||
PrintAndLogEx(INFO, "Gather tag information ");
|
PrintAndLogEx(INFO, "Gather tag information ");
|
||||||
PrintAndLogEx(INFO, "To be done!");
|
PrintAndLogEx(INFO, "To be done!");
|
||||||
|
|
||||||
char ctmp = tolower(param_getchar(Cmd, 0));
|
char ctmp = tolower(param_getchar(Cmd, 0));
|
||||||
if (ctmp == 'h') return usage_hitag_info();
|
if (ctmp == 'h') return usage_hitag_info();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,48 +415,48 @@ int CmdLFHitagReader(const char *Cmd) {
|
||||||
if (htf == RHT2F_UID_ONLY) {
|
if (htf == RHT2F_UID_ONLY) {
|
||||||
PrintAndLogEx(SUCCESS, "Valid Hitag2 tag found - UID: %08x", id);
|
PrintAndLogEx(SUCCESS, "Valid Hitag2 tag found - UID: %08x", id);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
uint8_t *data = resp.d.asBytes;
|
uint8_t *data = resp.d.asBytes;
|
||||||
|
|
||||||
char filename[FILE_PATH_SIZE];
|
char filename[FILE_PATH_SIZE];
|
||||||
char *fnameptr = filename;
|
char *fnameptr = filename;
|
||||||
fnameptr += sprintf(fnameptr, "lf-hitag-");
|
fnameptr += sprintf(fnameptr, "lf-hitag-");
|
||||||
FillFileNameByUID(fnameptr, data, "-dump", 4);
|
FillFileNameByUID(fnameptr, data, "-dump", 4);
|
||||||
|
|
||||||
saveFile(filename, "bin", data, 48);
|
saveFile(filename, "bin", data, 48);
|
||||||
saveFileEML(filename, "eml", data, 48, 4);
|
saveFileEML(filename, "eml", data, 48, 4);
|
||||||
saveFileJSON(filename, "json", jsfHitag, (uint8_t *)data, 48);
|
saveFileJSON(filename, "json", jsfHitag, (uint8_t *)data, 48);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdLFHitagCheckChallenges(const char *Cmd) {
|
int CmdLFHitagCheckChallenges(const char *Cmd) {
|
||||||
|
|
||||||
UsbCommand c = { CMD_TEST_HITAGS_TRACES, {0, 0, 0}};
|
UsbCommand c = { CMD_TEST_HITAGS_TRACES, {0, 0, 0}};
|
||||||
char filename[FILE_PATH_SIZE] = { 0x00 };
|
char filename[FILE_PATH_SIZE] = { 0x00 };
|
||||||
size_t datalen = 0;
|
size_t datalen = 0;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
bool file_given = false;
|
bool file_given = false;
|
||||||
bool errors = false;
|
bool errors = false;
|
||||||
uint8_t cmdp = 0;
|
uint8_t cmdp = 0;
|
||||||
uint8_t *data = calloc(8 * 60, sizeof(uint8_t));
|
uint8_t *data = calloc(8 * 60, sizeof(uint8_t));
|
||||||
|
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||||
case 'h':
|
case 'h':
|
||||||
free(data);
|
free(data);
|
||||||
return usage_hitag_checkchallenges();
|
return usage_hitag_checkchallenges();
|
||||||
case 'f':
|
case 'f':
|
||||||
param_getstr(Cmd, cmdp+1, filename, sizeof(filename));
|
param_getstr(Cmd, cmdp + 1, filename, sizeof(filename));
|
||||||
res = loadFile(filename, "cc", data, 8 * 60, &datalen);
|
res = loadFile(filename, "cc", data, 8 * 60, &datalen);
|
||||||
if ( res > 0 ) {
|
if (res > 0) {
|
||||||
errors = true;
|
errors = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(c.d.asBytes, data, datalen);
|
memcpy(c.d.asBytes, data, datalen);
|
||||||
file_given = true;
|
file_given = true;
|
||||||
cmdp += 2;
|
cmdp += 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||||
|
@ -464,19 +464,19 @@ int CmdLFHitagCheckChallenges(const char *Cmd) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Validations
|
//Validations
|
||||||
if (errors) {
|
if (errors) {
|
||||||
free(data);
|
free(data);
|
||||||
return usage_hitag_checkchallenges();
|
return usage_hitag_checkchallenges();
|
||||||
}
|
}
|
||||||
|
|
||||||
//file with all the challenges to try
|
//file with all the challenges to try
|
||||||
c.arg[0] = (uint32_t)file_given;
|
c.arg[0] = (uint32_t)file_given;
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
free(data);
|
free(data);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,7 +484,7 @@ int CmdLFHitagWriter(const char *Cmd) {
|
||||||
UsbCommand c = { CMD_WR_HITAG_S, {0, 0, 0}};
|
UsbCommand c = { CMD_WR_HITAG_S, {0, 0, 0}};
|
||||||
hitag_data *htd = (hitag_data *)c.d.asBytes;
|
hitag_data *htd = (hitag_data *)c.d.asBytes;
|
||||||
hitag_function htf = param_get32ex(Cmd, 0, 0, 10);
|
hitag_function htf = param_get32ex(Cmd, 0, 0, 10);
|
||||||
|
|
||||||
switch (htf) {
|
switch (htf) {
|
||||||
case WHTSF_CHALLENGE: {
|
case WHTSF_CHALLENGE: {
|
||||||
num_to_bytes(param_get64ex(Cmd, 1, 0, 16), 8, htd->auth.NrAr);
|
num_to_bytes(param_get64ex(Cmd, 1, 0, 16), 8, htd->auth.NrAr);
|
||||||
|
@ -512,20 +512,20 @@ int CmdLFHitagWriter(const char *Cmd) {
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 4000)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 4000)) {
|
||||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.arg[0] == false) {
|
if (resp.arg[0] == false) {
|
||||||
PrintAndLogEx(DEBUG, "DEBUG: Error - hitag write failed");
|
PrintAndLogEx(DEBUG, "DEBUG: Error - hitag write failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdLFHitagDump(const char *Cmd) {
|
int CmdLFHitagDump(const char *Cmd) {
|
||||||
PrintAndLogEx(INFO, "Dumping of tag memory");
|
PrintAndLogEx(INFO, "Dumping of tag memory");
|
||||||
PrintAndLogEx(INFO, "To be done!");
|
PrintAndLogEx(INFO, "To be done!");
|
||||||
|
|
||||||
char ctmp = tolower(param_getchar(Cmd, 0));
|
char ctmp = tolower(param_getchar(Cmd, 0));
|
||||||
if (ctmp == 'h') return usage_hitag_dump();
|
if (ctmp == 'h') return usage_hitag_dump();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,12 +191,12 @@ uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, ui
|
||||||
for (int j = 0; j < data_len && j / 18 < 18; j++) {
|
for (int j = 0; j < data_len && j / 18 < 18; j++) {
|
||||||
|
|
||||||
uint8_t parityBits = parityBytes[j >> 3];
|
uint8_t parityBits = parityBytes[j >> 3];
|
||||||
if ( protocol != LEGIC
|
if (protocol != LEGIC
|
||||||
&& protocol != ISO_14443B
|
&& protocol != ISO_14443B
|
||||||
&& protocol != ISO_7816_4
|
&& protocol != ISO_7816_4
|
||||||
&& protocol != PROTO_HITAG
|
&& protocol != PROTO_HITAG
|
||||||
&& (isResponse || protocol == ISO_14443A)
|
&& (isResponse || protocol == ISO_14443A)
|
||||||
&& (oddparity8(frame[j]) != ((parityBits >> (7 - (j & 0x0007))) & 0x01))) {
|
&& (oddparity8(frame[j]) != ((parityBits >> (7 - (j & 0x0007))) & 0x01))) {
|
||||||
|
|
||||||
snprintf(line[j / 18] + ((j % 18) * 4), 110, "%02x! ", frame[j]);
|
snprintf(line[j / 18] + ((j % 18) * 4), 110, "%02x! ", frame[j]);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -244,12 +244,12 @@ int saveFileJSON(const char *preferredName, const char *suffix, JSONFileType fty
|
||||||
memcpy(uid, data, 4);
|
memcpy(uid, data, 4);
|
||||||
|
|
||||||
JsonSaveBufAsHexCompact(root, "$.Card.UID", uid, sizeof(uid));
|
JsonSaveBufAsHexCompact(root, "$.Card.UID", uid, sizeof(uid));
|
||||||
|
|
||||||
for (int i = 0; i < (datalen / 4); i++) {
|
for (int i = 0; i < (datalen / 4); i++) {
|
||||||
char path[PATH_MAX_LENGTH] = {0};
|
char path[PATH_MAX_LENGTH] = {0};
|
||||||
sprintf(path, "$.blocks.%d", i);
|
sprintf(path, "$.blocks.%d", i);
|
||||||
JsonSaveBufAsHexCompact(root, path, data + (i * 4), 4);
|
JsonSaveBufAsHexCompact(root, path, data + (i * 4), 4);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -313,10 +313,10 @@ int loadFile(const char *preferredName, const char *suffix, void *data, size_t m
|
||||||
retval = 3;
|
retval = 3;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( bytes_read != maxdatalen ) {
|
if (bytes_read != maxdatalen) {
|
||||||
PrintAndLogDevice(WARNING, "Warning, bytes read exeed calling array limit. Max bytes is %d bytes", maxdatalen);
|
PrintAndLogDevice(WARNING, "Warning, bytes read exeed calling array limit. Max bytes is %d bytes", maxdatalen);
|
||||||
bytes_read = maxdatalen;
|
bytes_read = maxdatalen;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy((data), dump, bytes_read);
|
memcpy((data), dump, bytes_read);
|
||||||
|
@ -470,7 +470,7 @@ int loadFileJSON(const char *preferredName, const char *suffix, void *data, size
|
||||||
|
|
||||||
if (!strcmp(ctype, "hitag")) {
|
if (!strcmp(ctype, "hitag")) {
|
||||||
size_t sptr = 0;
|
size_t sptr = 0;
|
||||||
for (int i = 0; i < (maxdatalen/4); i++) {
|
for (int i = 0; i < (maxdatalen / 4); i++) {
|
||||||
if (sptr + 4 > maxdatalen) {
|
if (sptr + 4 > maxdatalen) {
|
||||||
retval = 5;
|
retval = 5;
|
||||||
goto out;
|
goto out;
|
||||||
|
|
|
@ -59,7 +59,7 @@ typedef enum {
|
||||||
// jsf14b,
|
// jsf14b,
|
||||||
// jsf15,
|
// jsf15,
|
||||||
// jsfLegic,
|
// jsfLegic,
|
||||||
// jsfT55xx,
|
// jsfT55xx,
|
||||||
} JSONFileType;
|
} JSONFileType;
|
||||||
|
|
||||||
int fileExists(const char *filename);
|
int fileExists(const char *filename);
|
||||||
|
|
|
@ -21,36 +21,36 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
RHTSF_CHALLENGE = 01,
|
RHTSF_CHALLENGE = 01,
|
||||||
RHTSF_KEY = 02,
|
RHTSF_KEY = 02,
|
||||||
WHTSF_CHALLENGE = 03,
|
WHTSF_CHALLENGE = 03,
|
||||||
WHTSF_KEY = 04,
|
WHTSF_KEY = 04,
|
||||||
RHT2F_PASSWORD = 21,
|
RHT2F_PASSWORD = 21,
|
||||||
RHT2F_AUTHENTICATE = 22,
|
RHT2F_AUTHENTICATE = 22,
|
||||||
RHT2F_CRYPTO = 23,
|
RHT2F_CRYPTO = 23,
|
||||||
WHT2F_CRYPTO = 24,
|
WHT2F_CRYPTO = 24,
|
||||||
RHT2F_TEST_AUTH_ATTEMPTS = 25,
|
RHT2F_TEST_AUTH_ATTEMPTS = 25,
|
||||||
RHT2F_UID_ONLY = 26,
|
RHT2F_UID_ONLY = 26,
|
||||||
} hitag_function;
|
} hitag_function;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t password[4];
|
uint8_t password[4];
|
||||||
} PACKED rht2d_password;
|
} PACKED rht2d_password;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t NrAr[8];
|
uint8_t NrAr[8];
|
||||||
uint8_t data[4];
|
uint8_t data[4];
|
||||||
} PACKED rht2d_authenticate;
|
} PACKED rht2d_authenticate;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t key[6];
|
uint8_t key[6];
|
||||||
uint8_t data[4];
|
uint8_t data[4];
|
||||||
} PACKED rht2d_crypto;
|
} PACKED rht2d_crypto;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
rht2d_password pwd;
|
rht2d_password pwd;
|
||||||
rht2d_authenticate auth;
|
rht2d_authenticate auth;
|
||||||
rht2d_crypto crypto;
|
rht2d_crypto crypto;
|
||||||
} hitag_data;
|
} hitag_data;
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,35 +83,35 @@ typedef enum SOF_TYPE {
|
||||||
HT_FAST_ADVANCED,
|
HT_FAST_ADVANCED,
|
||||||
HT_ONE,
|
HT_ONE,
|
||||||
HT_NO_BITS
|
HT_NO_BITS
|
||||||
} stype;
|
} stype;
|
||||||
|
|
||||||
struct hitagS_tag {
|
struct hitagS_tag {
|
||||||
PSTATE pstate; //protocol-state
|
PSTATE pstate; //protocol-state
|
||||||
TSATE tstate; //tag-state
|
TSATE tstate; //tag-state
|
||||||
uint32_t uid;
|
uint32_t uid;
|
||||||
uint8_t pages[64][4];
|
uint8_t pages[64][4];
|
||||||
uint64_t key;
|
uint64_t key;
|
||||||
uint8_t pwdl0, pwdl1, pwdh0;
|
uint8_t pwdl0, pwdl1, pwdh0;
|
||||||
//con0
|
//con0
|
||||||
int max_page;
|
int max_page;
|
||||||
stype mode;
|
stype mode;
|
||||||
//con1
|
//con1
|
||||||
bool auth; //0=Plain 1=Auth
|
bool auth; //0=Plain 1=Auth
|
||||||
bool TTFC; //Transponder Talks first coding. 0=Manchester 1=Biphase
|
bool TTFC; //Transponder Talks first coding. 0=Manchester 1=Biphase
|
||||||
int TTFDR; //data rate in TTF Mode
|
int TTFDR; //data rate in TTF Mode
|
||||||
int TTFM; //the number of pages that are sent to the RWD
|
int TTFM; //the number of pages that are sent to the RWD
|
||||||
bool LCON; //0=con1/2 read write 1=con1 read only and con2 OTP
|
bool LCON; //0=con1/2 read write 1=con1 read only and con2 OTP
|
||||||
bool LKP; //0=page2/3 read write 1=page2/3 read only in Plain mode and no access in authenticate mode
|
bool LKP; //0=page2/3 read write 1=page2/3 read only in Plain mode and no access in authenticate mode
|
||||||
//con2
|
//con2
|
||||||
//0=read write 1=read only
|
//0=read write 1=read only
|
||||||
bool LCK7; //page4/5
|
bool LCK7; //page4/5
|
||||||
bool LCK6; //page6/7
|
bool LCK6; //page6/7
|
||||||
bool LCK5; //page8-11
|
bool LCK5; //page8-11
|
||||||
bool LCK4; //page12-15
|
bool LCK4; //page12-15
|
||||||
bool LCK3; //page16-23
|
bool LCK3; //page16-23
|
||||||
bool LCK2; //page24-31
|
bool LCK2; //page24-31
|
||||||
bool LCK1; //page32-47
|
bool LCK1; //page32-47
|
||||||
bool LCK0; //page48-63
|
bool LCK0; //page48-63
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
function wait4proxmark_Linux {
|
function wait4proxmark_Linux {
|
||||||
echo >&2 "Waiting for Proxmark to appear..."
|
echo >&2 "Waiting for Proxmark to appear..."
|
||||||
while [ ! -c /dev/ttyACM? -a ! -L /dev/pm3-? ]; do
|
while [ ! -c /dev/ttyACM? -a ! -c /dev/pm3-? ]; do
|
||||||
sleep .1
|
sleep .1
|
||||||
done
|
done
|
||||||
local PM3=`ls -1 /dev/pm3-? /dev/ttyACM? 2>/dev/null | head -1`
|
local PM3=`ls -1 /dev/pm3-? /dev/ttyACM? 2>/dev/null | head -1`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue