Commit Graph
966 Commits
Author SHA1 Message Date
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
Niel Nielsen fc2fcc890c Add files via upload
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-08-26 16:07:37 +02:00
Niel Nielsen d2f82a5cd9 ADD battery drain to hw status
Battery SoC......... 54 %
  Battery voltage..... 3919 mV
  Battery current..... -72 mA (discharging)
  Remaining capacity.. 255 mAh
  Battery drain....... 72 mA (approx 3 h 32 min left)      ← new
  Temp (gauge)........ 54.5 C
  Full charge cap..... 480 mAh (design 500)
  Battery health...... 96 % (needs a full cycle to be accurate)


Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-08-25 23:01:04 +02:00
Niel Nielsen c65cb3c600 Define BWM_GAUGE_FCC and calculate battery health
Added FullChargeCapacity definition and battery health calculation.

Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-08-25 21:02:11 +02:00
Niel Nielsen 98c60d408f Improve USB auto power-off behavior
Refactor auto power-off logic to ensure it only triggers after USB has been present during the session.

Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-08-25 13:07:43 +02:00
Niel Nielsen 025c714ae5 Optimize USB auto-off polling and remove grace period
Reduced the polling interval for USB power checks and removed the grace period for auto-off functionality.

Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-08-25 12:43:53 +02:00
Niel Nielsen 8d6cccd4ca Rename battery temperature log to gauge temperature
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-08-25 12:43:53 +02:00
Niel Nielsen ed06150edc Implement automatic power-off on USB unplug
Added automatic power-off feature on USB unplug with configurable grace period and polling interval.

Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-08-25 12:43:53 +02:00
Devin Ronge ee90190928 add a timeout parameter to the hw qc_pm5 command and ensure rgb led is off at the conclusion of the test 2026-08-25 12:19:04 +02:00
Niel Nielsen 4d529bc4d7 CHANGE: Battery temp to Temp (gauge), ADD: Dim green LED when on battery only 2026-08-24 21:05:00 +02:00
Niel Nielsen 9e0de43ddc Rename battery temperature log to gauge temperature
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-08-24 21:05:00 +02:00
Niel Nielsen fb3ec70aec FIX only use BWM functions is BWM is seated 2026-08-24 17:57:50 +02:00
Niel Nielsen 190ed8a990 ADD: BWM status includes AW32001ECSR registerd, Charging set to 256mAh and keeps BWM safety guards for temperature 2026-08-23 20:31:01 +02:00
Niel Nielsen 7377dae83d Add files via upload
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-08-23 14:17:50 +02:00
Niel Nielsen cc98f9560b ADD: hw bwmsetcap commandhandler
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-08-23 13:23:08 +02:00
Niel Nielsen d8ff5594e7 Add BWM charger kick and battery status functions
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-08-23 11:20:13 +02:00
Antiklesys 6a317bdacc Added CMD_HF_ICLASS_RAW
Raw iCLASS reader exchange that leaves the field ON
2026-08-21 12:45:46 +08:00
Nemanja Nedeljkovic 6507b8f36b feat(pm5): hf tune --rgb / lf tune --rgb - antenna RGB as a tuning meter
Adds an opt-in `--rgb` flag to the continuous `hf tune` / `lf tune` commands that
mirrors the antenna tuning level on the PM5 antenna RGB LED: blue = low, green =
mid, red = high, tracking the on-screen bar so you can find coupling (e.g. an
implant) by feel without watching the screen.

The colour is computed client-side from the same per-iteration voltage / running
peak the bar uses (so it matches the bar and auto-scales), and pushed to the
device via a new dumb CMD_PM5_RGB_SET {r,g,b}. That command is handled (#ifdef
PM5) by a dedicated AT32 RGB HAL module, common_arm/rgb/{rgb_apis.h,
rgb_hw_at32.c} (RgbLedSet(), I2C controller @ 0x48), wired into the armsrc
Makefile/CMake as SRC_RGB for PM5 only - so no other platform is affected and no
hardware code lands in shared files.
2026-08-20 11:55:55 +02:00
Nemanja Nedeljkovic ba315d8d58 fix(pm5): suppress bogus [FPGA] version section on PM5
PM5's FPGA (Gowin GW1NR) bitstream is loaded at runtime via `hw fpga config`
and is not compiled into the firmware; only the Xilinx fpga_pm3_hf.bit is pulled
in (to generate g_fpga_version_information[]) which PM5 never runs. So the
`[ FPGA ] fpga_pm3_hf.ncd image 2s30vq100` line described a bitstream unrelated
to the actual device.

- Firmware (appmain.c): omit the [FPGA] section from the version string on PM5
  (#ifndef PM5), since there's no meaningful built-in FPGA version to report.
- Client (cmdhw.c): skip the FPGA_TYPE "chip mismatch" check for PM5, which would
  otherwise trigger now that the section is gone.
2026-08-20 10:36:09 +02:00
Nemanja Nedeljkovic 6da7c77427 feat(pm5): report AT32 MCU, flash size and PM5 target in hw version/status
`hw version` and `hw status` decoded the reported chip id as an Atmel AT91
CIDR. On PM5 (AT32) the id is an ARM DBGMCU IDCODE, so it showed
"MCU Unknown", a bogus flash size (32 KB / 973% used) and "PM3 GENERIC".

- Client: when IfPm5(), print MCU "AT32F437" and the real flash size, and add
  a "PM5" target line, instead of running the AT91 decode.
- Firmware: the flash size can't be derived from the AT32 IDCODE, so the device
  now sends GetChipFlashSize(). It is appended AFTER the version string in the
  CMD_VERSION reply, so the wire layout is unchanged and it stays compatible in
  both directions (old client ignores the trailing bytes; new client length-
  guards and treats a missing value as 0). GetChipFlashSize() already exists for
  both AT91 and AT32.
2026-08-19 21:49:43 +02:00
Philippe Teuwen 52af3f11e2 rename a couple of commands 2026-08-19 15:51:54 +02:00
Philippe Teuwen b6752e9dde compile CMD_FPGA_CMD_SET_PWR_PWM_LOW_COUNT only for pm5 2026-08-19 15:51:54 +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
Philippe Teuwen d2a8cca233 Add pm5 capabilities 2026-08-19 12:04:33 +02:00
Philippe Teuwen 436bbed4a2 Add placeholder for CMD_MAIN_CHIP_UNIQUEID 2026-08-19 12:04:32 +02:00
iceman1001 6fe58f8e3c several coverity fixes 2026-07-02 16:29:42 +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
kormax 4ad136b5db Implement 'hf felica sim' command 2026-06-12 18:31:57 +03:00
Philippe Teuwen 607737e52e counterfeit ULC: need to merge nonce collection in auth logic for proper timings 2026-06-10 00:39:46 +02:00
CinderSocket 81a5211594 Fix a situation where memory is improperly cleared 2026-06-07 16:37:32 -07:00
Philippe Teuwen ff04e1ea9a hf mfu cauth: add -c to collect nonces 2026-06-07 22:58:39 +02:00
Philippe Teuwen fb238015fa hf mfu sim --1a2-mirror 2026-06-04 20:19:15 +02:00
Antiklesys abe54994d2 Implemented SC operations 2026-05-11 13:54:49 +08:00
Joe Rozner 73799a6c69 Raise simaid selectaid_response cap to 256
The selectaid_response buffer in `hf 14a simaid` was capped at 100
bytes, which is well below the ISO 14443A frame maximum of 256 bytes
and prevents users from emulating tags whose SELECT AID response is
larger than a trivial status word.

This bumps selectaid_response from 100 to 256 in all three locations
(ARM packet handler, client locals, client payload struct) along with
the argparse help text. getdata_response is left at 100. The payload
struct overlays PM3_CMD_DATA_SIZE (512) via packet->data.asBytes;
with the new sizes it totals 435 bytes, so it still fits.

Pairs with the earlier tosend bounds check / DYNAMIC_MODULATION_BUFFER2
fix, which raised the actual transmit ceiling to the 256-byte frame
limit — this change lets callers supply a response up to that limit.
2026-04-22 23:38:18 -07:00
iceman1001 d3b7cbb3ff remove debug statements 2026-04-22 07:25:50 +07:00
iceman1001 5b3a6387ee annoyed 2026-04-21 11:14:23 +07:00
Philippe Teuwen 88d20bd4f2 make style 2026-04-13 09:35:02 +02:00
Iceman fc3dbe56bd Merge pull request #3208 from R4H33M/iclass-page-support
Add --page flag to hf iclass dump
2026-04-13 08:18:07 +07:00
iceman1001 aa1c1510fd remove debug text 2026-04-05 22:30:54 +07:00
Raheem Idowu 22dae554c7 hf iclass dump --page support 2026-04-04 17:15:13 -04:00
iceman1001 d8d221bc81 add reference to blacktears 2026-04-03 12:20:59 +07:00
iceman1001 c33f10f56b style 2026-04-03 11:46:58 +07:00
Antiklesys 519884aa01 Added secc support to jam custom payload values 2026-04-02 21:02:15 +08:00
kormax 753eb0737a Display a message when automatic field timeout is turned on 2026-03-31 20:49:03 +03:00
kormax 6c4b995e21 Introduce 'GetTickCountLabel' for detecting RTCC reconfigurations 2026-03-31 20:42:15 +03:00
kormax b443fc7723 Add 'hf.field.timeout' to prefs 2026-03-31 12:02:23 +03:00
Antiklesys 5236a13066 SECC Part 2 (fixed) 2026-03-30 23:50:58 +08:00
iceman1001 0d63e53a77 apply sanity checks for "smart upload" 2026-03-24 13:52:13 +07:00
xNovyz 52676ebbd4 style: whitespace fixes 2026-03-11 22:41:21 +01:00
xNovyz 286df8f4eb feat(14b): add interactive hf 14b tearoff command
Add an interactive command for performing tear-off attacks on ST25TB/SRx
monotonic counter blocks. This exploits EEPROM tearing to increment
counters that normally can only be decremented, based on the
near-field-chaos project by SecLabz.

The command sweeps tear-off timing from --start downward in --adj
microsecond steps, automatically consolidates partial writes, verifies
stability across multiple reads, and reports progress in real-time with
color-coded output.

Performance optimizations:
- One-time full iso14443b_setup() at start; subsequent field cycles use
  lightweight tearoff_field_on()/tearoff_field_off() that skip FPGA
  bitstream reload and buffer reallocation
- Periodic CMD_WTX keepalives to prevent USB timeouts during long attacks
- Calls FpgaResetBitstream() on exit to ensure clean FPGA state

Usage: hf 14b tearoff -b <block> -d <target> [--start <us>] [--adj <us>]
2026-03-11 21:43:37 +01:00