add hf thinfilm sniff, and hold the tag's real frame period

hf thinfilm sniff passively records the frames a Kovio tag beams at a reader.
Kovio is tag-talks-first and the reader never sends a command, so only the tag
side is decoded - use 'hf 14a sniff' to watch a reader's poll loop.  Same DMA
loop, overrun recovery and nibble de-interleave as SniffIso14443a().

ManchesterDecoding_Thinfilm() is no longer static and takes non_real_time, the
same way ManchesterDecodingEx() does.  A DMA sniff loop cannot timestamp with
GetCountSspClk(); the clock has run on past the frame by the time the samples
are processed.

Only the decoder is RAMFUNC (724 bytes), not the sniff loop, since dropping the
Miller decode roughly halves the per sample work.  The loop counts overrun
recoveries and DMA stalls separately, so a lossy capture says so instead of
looking like a quiet tag.

With that, the sim's frame period could be measured instead of guessed.  A
genuine tag repeats every 65536 carrier periods - 2**16, it clocks a 16 bit
counter off the carrier - holding that to within 65520..65920.  So 25% duty
cycle, not the continuous beam assumed when the gap was shortened to 500us in
a96756033.  Revert to the tag's real rate.

SimulateThinFilm() now waits on the previous frame start rather than delaying a
fixed amount, so the field poll comes out of the gap instead of adding on top of
it, and the period stays right if the poll cost ever changes.  Measured back
with a second pm3 sniffing: 65561 carrier periods against the genuine tag's
65588, inside the tag's own jitter.

Rig: pm3 simulating, second pm3 sniffing, Pixel 9a reading, all three at once.
Builds clean for PM3RDV4 and PM5.

Co-Authored-By: Claude Opus 5 (1M context)
This commit is contained in:
iceman1001andClaude Opus 5 (1M context) committed 2026-09-12 15:09:53 +02:00
1 parent 9a8e179266
commit 696b8357b6
4 files changed
+239 -8

No files matched your search

+54
View File
@@ -205,6 +205,59 @@ int CmdHfThinFilmSim(const char *Cmd) {
return PM3_SUCCESS;
}
static int CmdHfThinFilmSniff(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf thinfilm sniff",
"Sniff the frames a Thinfilm / NFC Barcode tag beams at a reader.\n"
"The tag talks first and the reader sends nothing, so only the tag side\n"
"is decoded. Use `hf thinfilm list` to view collected data.",
"hf thinfilm sniff\n"
"hf thinfilm sniff -i"
);
void *argtable[] = {
arg_param_begin,
arg_lit0("i", "interactive", "Console will not be returned until sniff finishes or is aborted"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
bool interactive = arg_get_lit(ctx, 1);
CLIParserFree(ctx);
clearCommandBuffer();
SendCommandNG(CMD_HF_THINFILM_SNIFF, NULL, 0);
if (interactive == false) {
PrintAndLogEx(INFO, "Press " _GREEN_("pm3 button") " to abort sniffing");
return PM3_SUCCESS;
}
PrintAndLogEx(INFO, "Press " _GREEN_("pm3 button") " or " _GREEN_("<Enter>") " to abort sniffing");
PacketResponseNG resp;
bool keypress = kbd_enter_pressed();
while (keypress == false) {
keypress = kbd_enter_pressed();
if (WaitForResponseTimeout(CMD_HF_THINFILM_SNIFF, &resp, 500)) {
break;
}
}
if (keypress) {
// inform device to break the sniff loop since client has exited
SendCommandNG(CMD_BREAK_LOOP, NULL, 0);
WaitForResponse(CMD_HF_THINFILM_SNIFF, &resp);
}
PrintAndLogEx(INFO, "Done!");
PrintAndLogEx(HINT, "Hint: Try `" _YELLOW_("hf thinfilm list") "` to view captured tracelog");
PrintAndLogEx(HINT, "Hint: Try `" _YELLOW_("trace save -h") "` to save tracelog for later analysing");
return PM3_SUCCESS;
}
static int CmdHfThinFilmList(const char *Cmd) {
return CmdTraceListAlias(Cmd, "hf thinfilm", "thinfilm");
}
@@ -214,6 +267,7 @@ static command_t CommandTable[] = {
{"info", CmdHfThinFilmInfo, IfPm3NfcBarcode, "Tag information"},
{"list", CmdHfThinFilmList, AlwaysAvailable, "List NFC Barcode / Thinfilm history"},
{"sim", CmdHfThinFilmSim, IfPm3NfcBarcode, "Fake Thinfilm tag"},
{"sniff", CmdHfThinFilmSniff, IfPm3NfcBarcode, "Sniff Thinfilm tag communication"},
{NULL, NULL, NULL, NULL}
};