Commit Graph
142 Commits
Author SHA1 Message Date
iceman1001andClaude Opus 5 (1M context) 5b909402b5 BigBuf: stop narrowing sizes, and size the 14a modulation buffer to fit
Three things that all cost memory or correctness once BigBuf is larger
than 64KB, which it already is on PM5.

BigBuf_max_traceLen() returned a uint16_t while s_bigbuf_hi is a
uint32_t. At 33272 on AT91 that is harmless; on AT32, where BigBuf runs
to several hundred kbyte, it truncates and LF sampling asks for a
fraction of the buffer that is there. Widened, along with the four
callers that assigned it straight back into a uint16_t.

BigBuf_malloc() and BigBuf_calloc() took a uint16_t chunksize, so a
request of exactly 65536 arrived as 0 and anything above wrapped. It
returned NULL for the 65536 case by accident, not by design. Both take a
uint32_t now and the guard tests the upper bound explicitly, so an
oversized request fails like any other allocation that does not fit.

The 14a tag simulation allocated its dynamic modulation buffer as a flat
512, or 4096 for ST25TA. prepare_tag_modulation() memcpy's the encoded
answer out of the ToSend buffer and tosend_stuffbit() hard caps that at
TOSEND_BUFFER_SIZE, so 1788 of ST25TA's 4096 could never be reached --
it was the largest single allocation of any tag simulation for nothing.
Meanwhile 512 is 68 bytes short of what a full 64 byte response encodes
to, at 9 bytes per byte plus 4, so those answers were refused at
modulation time.

Both are now derived from the response size and capped at what ToSend
can hold: 580 for the default tag types, 2308 for ST25TA. That also
fixes the reason the 4096 never helped -- all six call sites passed the
512 macro as max_buffer_size rather than the size actually allocated, so
ST25TA allocated 4096 and then bounds checked against 512.

Worst case for a simulation that also holds emulator memory drops from
12247 bytes of BigBuf to 10459.

Built for client, RDV4 and PM3GENERIC. Not yet run on hardware.

Co-Authored-By: Claude Opus 5 (1M context)
2026-09-14 13:06:14 +02:00
Philippe Teuwen 7fb8927523 Fix streaming bug affecting mostly the pm5
Bug triggered with:
lf read -s 50000
hw ping

ReadLF_realtime() in lfsampling.c never knew how many samples the client wanted — for the realtime path, lf_sample_payload_t.samples was never populated on the client side, and the ARM handler in appmain.c (CMD_LF_ACQ_RAW_ADC/CMD_LF_SNIFF_RAW_ADC) ignored it anyway. So the device just streamed samples indefinitely, only checking for a stop request roughly once per 64-sample USB burst, and even after noticing it, flushed one more trailing partial burst via async_usb_write_stop().

Meanwhile the client (WaitForRawDataTimeout in comms.c) stops listening in raw mode the instant it has collected exactly the number of bytes it asked for (e.g. 50000), then switches back to normal framed-packet parsing. Since the device kept sending more bytes past that point, those extra bytes sat unread in the pipe and got misinterpreted as a PacketResponseNGPreamble/OLD-frame header, corrupting every subsequent USB exchange (hw ping, etc.) — reproducible even with a plain lf read -s 50000, no trigger/COTAG needed.

Moreover, we make sure the client doesn't stop listening, even briefly, during stream reception.
2026-08-26 20:16:46 +02:00
dxl e3511c5350 Used HAL layer
in appmain.c and cmd added.
in cmd.c and add some code for test CEP
in em4x50.c(Do not timeout--)
in em4x70.c
in emvsim.c
in epa.c
in felica.c
in felicasim.c
in felicasim.c
in hfops.c
in hfsnoop.c
in hitag2.c
in hitag_common.c(Cross-platform implementation is incomplete.)
in hitagS.c
in hitagu.c
in i2c.c(Incomplete, continue to abstract.)
in i2c_direct.c
in iclass.c
in iso14443a.c(Sniff no finish yet)
in iso14443b.c and fixed bug for st25
in iso15693.c
in legicrf.c
in legicrfsim.c
in lfadc.c(lf_count_edge_periods_ex() improved)
in lfops.c(TI tag no finish yet)
in lfsampling.c
in lfzx.c
in mifarecmd.c
in mifaredesfire.c
in mifaresim.c
in mifaresniff_disabled.c
in mifareutil.c
in pcf7931.c
in sam_xxx
in secc & seos
in start.c
in thinfilm.c
in utils
2026-08-19 15:32:39 +02:00
towelbyte c1cefd6e38 Complete and working reimplementation of COTAG support
- "lf cotag reader": now behaves mostly the same as "lf read",
   except it is dedicated for COTAG.
	- It makes sure to send COTAG start sequence and to use
          real time sampling mode to get enough samples.

- "lf cotag demod": Working client-side COTAG demodulation implementation
   (high-low raw demod + Manchester demodulation from high/low demod).
	- Now uses samples directly from g_GraphBuffer
	- Supports 3 types of COTAG preamble (1 active, 2 passive), which
          can start anywhere in the samples.
	- Prints full 128-bits of COTAG tag data in 3 formats: raw,
          groupped by nibbles, and in hex, and identifies and
          prints out the card number.

Signed-off-by: andrej@towelbyte.net
2026-06-12 22:49:06 +02:00
iceman1001 6ee974b935 swapped from bigbuf malloc calls to calloc calls on device side. Now all allocations should start from a known state of memory 2025-08-20 16:23:36 +02:00
iceman1001 875b3c44b4 unify text - step 1 2025-03-25 10:12:16 +01:00
douniwan5788 112caec054 refactor: lf config renames 2024-08-27 23:45:42 +08:00
iceman1001 6bdfe11c1a minor fixes 2024-05-28 10:00:11 +02:00
iceman1001 369db7c9d7 style 2024-05-27 20:29:02 +02:00
iceman1001 cb937a3f57 fix overwriting return value in one case 2024-05-14 10:59:10 +02:00
iceman1001 4304372858 tweaking felica timings to see if it gets better results 2024-04-22 10:41:28 +02:00
iceman1001 a913b2c662 style 2023-12-01 10:59:18 +01:00
wh201906 3ee13c9ba6 Apply suggestions from @henrygab
Check if memory allocation fails
Fix memory leak
Initialize struct in declaration
Add/Fix some notes
Remove unlikely() in favor of readability
Remove a hard-coded magic number
2023-11-15 18:04:52 +08:00
wh201906 ab9f49f86e Some minor fixes
Use longer timeout in WaitForRawDataTimeout() to handle CMD_WTX
Fix a wrong type
Apply changes to other similar part
Remove unused instructions
2023-11-14 10:46:45 +08:00
wh201906 b4cc7c02cd Real-time LF sampling mode on armsrc 2023-11-14 01:43:20 +08:00
yah01 9d07ee497c Improve lf sampling performance
Signed-off-by: yah01 <yah2er0ne@outlook.com>
2023-10-27 13:47:26 +08:00
Henry Gabryjelski 78262139ec more const for lfsampling and lfzx 2023-08-14 23:07:19 -07:00
iceman1001 08d2c2f1a5 style 2023-02-11 11:42:58 +01:00
wh201906 f4879fdc17 Bypass some functions if bps is not 8 2023-01-22 15:41:07 +00:00
wh201906 239a8646b2 Fix the wrong sample count when bps!=8 2023-01-22 15:38:09 +00:00
iceman1001 2dd250ab80 fix initialization of bitstream buffer 2022-04-10 13:15:24 +02:00
Philippe Teuwen b703bb746b Adapting license headers, WIP 2022-01-06 02:20:38 +01:00
Łukasz Jurczyk 218a4ba2ec Added ledcontrol to lf functions 2021-11-18 15:00:54 +01:00
Philippe Teuwen 5b54385347 rename globals 2021-08-21 23:08:26 +02:00
Philippe Teuwen f4f14317e1 rename typedef structs 2021-08-21 22:24:58 +02:00
iceman1001 8472c6ffe7 make style 2021-07-29 15:00:00 +02:00
iceman1001 765d2acbb0 t55xx detect/read/write/dump etc will fail if you set lf config to something. Moved the reset / restore of lf config to device side for T55XX readblock. t55xx sniff still obeys lf config since it uses lf sniff beneath. 2021-07-29 10:51:31 +02:00
iceman1001 bc5d7084c3 change t55xx detect to unset lf config decimation to 1 if its value wasnt 1. Thanks to @mwalker33 2021-07-28 09:51:35 +02:00
iceman1001 a6712295c7 textual - hw status on device side 2021-05-11 16:11:33 +02:00
iceman1001 e3aa035be7 fix: lf config set decimate or divisor to 8 is now possible 2021-02-03 16:00:33 +01:00
Philippe Teuwen 7cd80611d3 #makestyleday 2020-12-12 14:46:40 +01:00
iceman1001 2613284dfc fix lf search - cotag exiting on deviceside 2020-12-01 17:06:49 +01:00
Philippe Teuwen c3c59e35cb make style 2020-09-30 14:27:19 +02:00
Philippe Teuwen 1e19a7216a Avoid first spurious samples in LF sniff modes, prevents false triggering 2020-09-20 12:59:30 +02:00
Philippe Teuwen 35e276f8ed Add options to 'lf sniff' for repeated acquisitions 2020-09-20 11:37:51 +02:00
Philippe Teuwen c994323105 Unify 'lf read' and 'lf cmdread options', add options to cmdread 2020-09-16 12:59:42 +02:00
iceman1001 0be35a8e7e style 2020-09-07 10:35:09 +02:00
Philippe Teuwen b751354ea2 hf 14a: add config loopholes to deal with badly configured cards: invalid ATQA, invalid BCC, invalid SAK 2020-09-07 00:50:27 +02:00
iceman1001 47f1bd2d6c lfsampling adaptations 2020-09-06 18:32:23 +02:00
iceman1001 32c614db7b fix cotag memory bugs. was off-by-one 2020-08-25 15:34:10 +02:00
iceman1001 0641ada091 since t55xx chkpwd uses EM for pwd storage 2020-08-21 14:50:14 +02:00
Philippe Teuwen 4ed57c7c4d make style 2020-08-13 12:25:04 +02:00
iceman1001 85053d106f adapt to fpga changes. And bug hunting COTAG functionality that doesnt work 2020-07-02 12:34:48 +02:00
iceman1001 d9f606d70b more debugstatements 2020-06-23 11:21:17 +02:00
iceman1001 ba6bc0ecef chg: 'lf io watch' - uses NG and reports back to client 2020-06-22 12:57:28 +02:00
iceman1001 3832cf26fd color 2020-06-11 19:20:59 +02:00
iceman1001 9d1cbaddf9 text 2020-06-10 08:56:45 +02:00
Philippe Teuwen cb8d589fc4 armsrc: clarify static vars vs global vars, part 3 2020-05-19 18:12:40 +02:00
Philippe Teuwen 3e7512a5d5 armsrc: clarify static vars vs global vars 2020-05-19 17:05:43 +02:00
Philippe Teuwen 026707b960 arm: fix prototypes 2020-05-11 13:48:57 +02:00