changed legic sim to have a different loop and exit message. Added some colors in output and the return codes on deviceside for legisim now uses the same PM3_E* styled

This commit is contained in:
iceman1001 2023-07-17 19:31:37 +02:00
parent 230f1c654b
commit c70e5beeac
3 changed files with 36 additions and 41 deletions

View file

@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
## [unreleased][unreleased]
- Changed `hf legic sim` - loop and return codes on deviceside updated to DEFINES (@iceman1001)
- Changed `hf legic einfo` - now accepts the three different cardsizes as params (@iceman1001)
- Fix `lf cotag reader -1` - now doesn't fail (@iceman1001)
- Added support for LZ4 compressed hadnested tables (@doegox)

View file

@ -96,13 +96,13 @@ static int8_t rx_bit(void) {
uint32_t bit_start = last_frame_end;
// wait for pause to end
if (!wait_for(RWD_PULSE, bit_start + RWD_TIME_1 * 3 / 2)) {
return -1;
if (wait_for(RWD_PULSE, bit_start + RWD_TIME_1 * 3 / 2) == false) {
return PM3_ERFTRANS;
}
// wait for next pause
if (!wait_for(RWD_PAUSE, bit_start + RWD_TIME_1 * 3 / 2)) {
return -1;
if (wait_for(RWD_PAUSE, bit_start + RWD_TIME_1 * 3 / 2) == false) {
return PM3_ERFTRANS;
}
// update bit and frame end
@ -110,7 +110,7 @@ static int8_t rx_bit(void) {
// check for code violation (bit to short)
if (last_frame_end - bit_start < RWD_TIME_PAUSE) {
return -1;
return PM3_ERFTRANS;
}
// apply threshold (average of RWD_TIME_0 and )
@ -235,7 +235,7 @@ static int32_t rx_frame(uint8_t *len) {
// check for code violation
if (i > RWD_CMD_TIMEOUT) {
return -1;
return PM3_ETIMEOUT;
}
}
@ -251,7 +251,7 @@ static int32_t rx_frame(uint8_t *len) {
// check for code violation and to short / long frame
if ((bit < 0) && ((*len < RWD_MIN_FRAME_LEN) || (*len > RWD_MAX_FRAME_LEN))) {
return -1;
return PM3_ERFTRANS;
}
// check for code violation caused by end of frame
@ -353,7 +353,7 @@ static int32_t setup_phase(legic_card_select_t *p_card) {
// wait for iv
int32_t iv = rx_frame(&len);
if ((len != 7) || (iv < 0)) {
return -1;
return PM3_ERFTRANS;
}
// configure prng
@ -375,19 +375,19 @@ static int32_t setup_phase(legic_card_select_t *p_card) {
// wait for ack
int32_t ack = rx_frame(&len);
if ((len != 6) || (ack < 0)) {
return -1;
return PM3_ERFTRANS;
}
// validate data
switch (p_card->tagtype) {
case 0:
if (ack != 0x19) return -1;
if (ack != 0x19) return PM3_ERFTRANS;
break;
case 1:
if (ack != 0x39) return -1;
if (ack != 0x39) return PM3_ERFTRANS;
break;
case 2:
if (ack != 0x39) return -1;
if (ack != 0x39) return PM3_ERFTRANS;
break;
}
@ -399,7 +399,7 @@ static int32_t setup_phase(legic_card_select_t *p_card) {
// the gap by one period.
last_frame_end += TAG_BIT_PERIOD;
return 0;
return PM3_SUCCESS;
}
static uint8_t calc_crc4(uint16_t cmd, uint8_t cmd_sz, uint8_t value) {
@ -414,7 +414,7 @@ static int32_t connected_phase(legic_card_select_t *p_card) {
// wait for command
int32_t cmd = rx_frame(&len);
if (cmd < 0) {
return -1;
return PM3_ETIMEOUT;
}
// check if command is LEGIC_READ
@ -425,8 +425,7 @@ static int32_t connected_phase(legic_card_select_t *p_card) {
// transmit data
tx_frame((crc << 8) | byte, 12);
return 0;
return PM3_SUCCESS;
}
// check if command is LEGIC_WRITE
@ -441,7 +440,7 @@ static int32_t connected_phase(legic_card_select_t *p_card) {
uint8_t calc_crc = calc_crc4(addr << 1, p_card->cmdsize, byte);
if (calc_crc != crc) {
Dbprintf("!!! crc mismatch: %x != %x !!!", calc_crc, crc);
return -1;
return PM3_ECRC;
}
// store data
@ -449,11 +448,10 @@ static int32_t connected_phase(legic_card_select_t *p_card) {
// transmit ack
tx_ack();
return 0;
return PM3_SUCCESS;
}
return -1;
return PM3_ERFTRANS;
}
//-----------------------------------------------------------------------------
@ -474,35 +472,30 @@ void LegicRfSimulate(uint8_t tagtype, bool send_reply) {
goto OUT;
}
uint16_t counter = 0;
LED_A_ON();
Dbprintf("Legic Prime, simulating uid: %02X%02X%02X%02X", legic_mem[0], legic_mem[1], legic_mem[2], legic_mem[3]);
Dbprintf("Legic Prime, simulating uid... " _YELLOW_("%02X%02X%02X%02X"), legic_mem[0], legic_mem[1], legic_mem[2], legic_mem[3]);
while (BUTTON_PRESS() == false) {
WDT_HIT();
if (counter >= 2000) {
if (data_available()) {
res = PM3_EOPABORTED;
break;
goto OUT;
}
counter = 0;
}
counter++;
// wait for carrier, restart after timeout
if (wait_for(RWD_PULSE, GetCountSspClk() + TAG_BIT_PERIOD) == false) {
continue;
}
// wait for connection, restart on error
if (setup_phase(&card)) {
if (setup_phase(&card) != PM3_SUCCESS) {
continue;
}
// connection is established, process commands until one fails
while (connected_phase(&card) == false) {
while (connected_phase(&card) != PM3_SUCCESS) {
WDT_HIT();
}
}
@ -510,11 +503,11 @@ void LegicRfSimulate(uint8_t tagtype, bool send_reply) {
OUT:
if (g_dbglevel >= DBG_ERROR) {
Dbprintf("Emulator stopped. Tracing: %d trace length: %d ", get_tracing(), BigBuf_get_traceLen());
Dbprintf("Emulator stopped. Trace length... " _YELLOW_("%d"), BigBuf_get_traceLen());
}
if (res == PM3_EOPABORTED)
DbpString("aborted by user");
DbpString("Aborted by user");
switch_off();
StopTicks();

View file

@ -536,20 +536,21 @@ static int CmdLegicSim(const char *Cmd) {
SendCommandNG(CMD_HF_LEGIC_SIMULATE, (uint8_t *)&payload, sizeof(payload));
PacketResponseNG resp;
PrintAndLogEx(INFO, "Press pm3-button to abort simulation");
bool keypress = kbd_enter_pressed();
while (keypress == false) {
keypress = kbd_enter_pressed();
PrintAndLogEx(INFO, "Press " _GREEN_("<Enter>") " or pm3-button to abort simulation");
for (;;) {
if (kbd_enter_pressed()) {
SendCommandNG(CMD_BREAK_LOOP, NULL, 0);
PrintAndLogEx(DEBUG, "User aborted");
break;
}
if (WaitForResponseTimeout(CMD_HF_LEGIC_SIMULATE, &resp, 1500)) {
break;
}
}
if (keypress)
SendCommandNG(CMD_BREAK_LOOP, NULL, 0);
PrintAndLogEx(INFO, "Done");
PrintAndLogEx(HINT, "Try `" _YELLOW_("hf legic list") "` to view trace log");
return PM3_SUCCESS;
}