Skip to content

Commit f8a2ced

Browse files
authored
Merge pull request #3195 from Antiklesys/master
Fixed hf secc sniff -j bug
2 parents 727d863 + 195f083 commit f8a2ced

File tree

2 files changed

+13
-130
lines changed

2 files changed

+13
-130
lines changed

armsrc/iso14443a.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
#include "mifare.h" // for iso14a_polling_frame_t structure
3939
#include "cmac_calc.h"
4040

41+
// Forward declaration: HID Config Card jam support (implemented in secc.c).
42+
// Called from SniffIso14443a when param bit 0x04 is set.
43+
bool hid_config_card_jam(const uint8_t *cmd, int len, uint8_t *dma_buf);
44+
4145
static uint32_t iso14a_timeout;
4246

4347
static uint8_t colpos = 0;
@@ -927,6 +931,11 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
927931
break;
928932
}
929933
}
934+
// HID Config Card jam: respond to A0 D4 00 00 00 in-band
935+
if ((param & 0x04) && Uart.len >= 8) {
936+
if (hid_config_card_jam(receivedCmd, Uart.len, (uint8_t *)dma->buf))
937+
data = dma->buf;
938+
}
930939
// ready to receive another command
931940
Uart14aReset();
932941
// reset the demod code, which might have been

armsrc/secc.c

Lines changed: 4 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -447,134 +447,8 @@ void SimulateHIDConfigCard(const hid_sim_payload_t *payload) {
447447
// ---------------------------------------------------------------------------
448448

449449
void SniffHIDConfigCard(uint8_t param) {
450-
bool do_jam = (param & 0x04) != 0;
451-
452-
// For non-jam sniff, delegate entirely to the standard sniffer.
453-
if (!do_jam) {
454-
SniffIso14443a(param);
455-
return;
456-
}
457-
458-
// Jam mode: own sniff loop with hid_config_card_jam() called inline.
459-
BigBuf_free();
460-
BigBuf_Clear_ext(false);
461-
462-
uint8_t *receivedCmd = BigBuf_calloc(MAX_FRAME_SIZE);
463-
uint8_t *receivedCmdPar = BigBuf_calloc(MAX_PARITY_SIZE);
464-
uint8_t *receivedResp = BigBuf_calloc(MAX_FRAME_SIZE);
465-
uint8_t *receivedRespPar = BigBuf_calloc(MAX_PARITY_SIZE);
466-
467-
Demod14aInit(receivedResp, MAX_FRAME_SIZE, receivedRespPar);
468-
Uart14aInit(receivedCmd, MAX_FRAME_SIZE, receivedCmdPar);
469-
470-
dmabuf8_t *dma = get_dma8();
471-
uint8_t *data = dma->buf;
472-
473-
if (FpgaSetupSscDma((uint8_t *)dma->buf, DMA_BUFFER_SIZE) == false) {
474-
BigBuf_free();
475-
return;
476-
}
477-
478-
bool triggered = !(param & 0x03);
479-
uint32_t rx_samples = 0;
480-
bool TagIsActive = false;
481-
bool ReaderIsActive = false;
482-
uint8_t previous_data = 0;
483-
int maxDataLen = 0, dataLen;
484-
uint16_t checker = 12000;
485-
486-
tUart14a *uart = GetUart14a();
487-
tDemod14a *demod = GetDemod14a();
488-
489-
clear_trace();
490-
set_tracing(true);
491-
LED_A_ON();
492-
493-
while (BUTTON_PRESS() == false) {
494-
WDT_HIT();
495-
496-
if (checker-- == 0) {
497-
if (data_available()) break;
498-
checker = 12000;
499-
}
500-
501-
int readBufDataP = data - dma->buf;
502-
int dmaBufDataP = DMA_BUFFER_SIZE - AT91C_BASE_PDC_SSC->PDC_RCR;
503-
dataLen = (readBufDataP <= dmaBufDataP)
504-
? dmaBufDataP - readBufDataP
505-
: DMA_BUFFER_SIZE - readBufDataP + dmaBufDataP;
506-
507-
if (dataLen > maxDataLen) {
508-
maxDataLen = dataLen;
509-
if (dataLen > (9 * DMA_BUFFER_SIZE / 10)) break;
510-
}
511-
if (dataLen < 1) continue;
512-
513-
if (AT91C_BASE_PDC_SSC->PDC_RCR == 0) {
514-
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t)dma->buf;
515-
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
516-
}
517-
if (AT91C_BASE_PDC_SSC->PDC_RNCR == 0) {
518-
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t)dma->buf;
519-
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
520-
}
521-
522-
LED_A_OFF();
523-
524-
if (rx_samples & 0x01) {
525-
if (!TagIsActive) {
526-
uint8_t readerdata = (previous_data & 0xF0) | (*data >> 4);
527-
if (MillerDecoding(readerdata, (rx_samples - 1) * 4)) {
528-
LED_C_ON();
529-
if (!triggered && (param & 0x02) && uart->len == 1 && uart->bitCount == 7)
530-
triggered = true;
531-
if (triggered) {
532-
if (!LogTrace(receivedCmd, uart->len,
533-
uart->startTime * 16 - DELAY_READER_AIR2ARM_AS_SNIFFER,
534-
uart->endTime * 16 - DELAY_READER_AIR2ARM_AS_SNIFFER,
535-
uart->parity, true))
536-
break;
537-
}
538-
if (uart->len >= 8) {
539-
if (hid_config_card_jam(receivedCmd, uart->len, (uint8_t *)dma->buf))
540-
data = dma->buf;
541-
}
542-
Uart14aReset();
543-
Demod14aReset();
544-
LED_B_OFF();
545-
}
546-
ReaderIsActive = (uart->state != STATE_14A_UNSYNCD);
547-
}
548-
549-
if (!ReaderIsActive) {
550-
uint8_t tagdata = (previous_data << 4) | (*data & 0x0F);
551-
if (ManchesterDecoding(tagdata, 0, (rx_samples - 1) * 4)) {
552-
LED_B_ON();
553-
if (!LogTrace(receivedResp, demod->len,
554-
demod->startTime * 16 - DELAY_TAG_AIR2ARM_AS_SNIFFER,
555-
demod->endTime * 16 - DELAY_TAG_AIR2ARM_AS_SNIFFER,
556-
demod->parity, false))
557-
break;
558-
if (!triggered && (param & 0x01))
559-
triggered = true;
560-
Uart14aReset();
561-
Demod14aReset();
562-
LED_C_OFF();
563-
}
564-
TagIsActive = (demod->state != DEMOD_14A_UNSYNCD);
565-
}
566-
}
567-
568-
previous_data = *data;
569-
rx_samples++;
570-
if (data == dma->buf + DMA_BUFFER_SIZE)
571-
data = dma->buf;
572-
else
573-
data++;
574-
}
575-
576-
FpgaDisableSscDma();
577-
set_tracing(false);
578-
LEDsoff();
579-
BigBuf_free();
450+
// Delegate entirely to SniffIso14443a.
451+
// When param bit 0x04 is set, SniffIso14443a calls hid_config_card_jam()
452+
// inline after each decoded reader frame (see iso14443a.c).
453+
SniffIso14443a(param);
580454
}

0 commit comments

Comments
 (0)