101 Commits
Author SHA1 Message Date
Tom HarknessandClaude Sonnet 5 ba4016d7e2 PM5 CEP: data_available() doesn't poll CEP, so CMD_BREAK_LOOP over a
Flipper link can't interrupt a running reader loop

Problem: triggering the Flipper FAP's built-in ReadHitag2 demo command
turns the RF field on and it stays on even after backing out of the
app - only an unrelated USB command clears it. data_available()
(armsrc/util.c) is the standard idiom LF/HF reader loops use to notice
an incoming CMD_BREAK_LOOP, but it only polled USB/BWM/FPC. CEP's own
transport PR never wired it in, so a Flipper-sent break is invisible
to any loop that was already running.

Fix: add cep_spi_rx_pending() to armsrc/pm5_cep.c/.h - a genuinely
non-blocking single SPI1 RDBF flag check, not a reuse of the existing
(bounded-wait) cep_spi_data_available(), since this gets called every
iteration of every reader loop in the codebase and needs to cost
nothing when idle. Wire it into data_available()/data_available_fast()
alongside the existing BWM/FPC branches, additive since CEP and BWM
can coexist.

Hardware-confirmed: field now drops promptly every cycle instead of
sticking on, across repeated ReadHitag2 attach/attempt/cancel cycles.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-04 14:36:03 +02:00
Travis Weathers 5c86fb47f1 fix(armsrc): poll the BWM link in data_available()
data_available() and data_available_fast() are how the device notices that
the host has asked a running command to stop. They branch on USB and on
WITH_FPC_USART_HOST, and never learned about the Proxmark5 BWM.

A PM5 with the wireless module builds PLATFORM=PM5 PLATFORM_EXTRAS=BWM,
which defines WITH_BWM_FORWARD. BTADDON errors out on PM5 and BWM errors
out on anything else (common_arm/Makefile.hal), so WITH_FPC_USART_HOST is
never defined on that build and both functions compile down to a USB-only
check.

Commands still arrive, because receive_ng() does poll the module
(armsrc/cmd.c). What was blind was the abort path: CMD_BREAK_LOOP is never
observed over BLE or WiFi, so every loop whose only exit is this check runs
until the button is pressed. That is 75 call sites across 26 files in
armsrc/, including the sniff, simulate and reader loops, so in practice a
wireless session cannot be interrupted at all. ReaderHitag() is the worst
case: with no tag on the antenna it has no other exit, so `lf search` alone
leaves the device answering nothing.

This is reachable with upstream tooling only: client/src/uart/ble_posix.c
is the native BLE transport, selected with `-p ble:<address-or-name>`, and
doc/md/PM5_Start_Here/PM5-BWM-USAGE.md documents both that and
`-p tcp:<host>:<port>` over the module's WiFi. Both share the same inbound
de-framer, so both are affected.

Folded into the existing preprocessor chain as an #elif, mirroring
receive_ng(), since the two transports are mutually exclusive by build.
USB is still tested first, so the module is only polled when USB has
nothing, exactly as the FPC branch behaves.

bwm_fwd_rxdata_available() is the same call receive_ng() already uses. When
the de-frame FIFO is empty it costs a flag test and one DMA counter read
(bwm_uart_rx_available()); it only walks bytes when bytes have actually
arrived, and those bytes are the abort. That mirrors the FPC branch, where
usart_rxdata_available() already calls usart_rx_poll() from these same two
functions. data_available_fast()'s only caller is the ReadLF_realtime()
sampling loop, which reaches it once per 64 saved samples; it is included
here so the two functions cannot drift apart again, which is how this bug
arose.

Object code is byte-identical on every platform that does not define
WITH_BWM_FORWARD. Built PLATFORM=PM3RDV4, PM3RDV4 with BTADDON, PM5 without
BWM and PM5 with BWM; only the last one changes:

  PM3RDV4           74f7f7a1...  ->  74f7f7a1...  identical
  PM3RDV4 BTADDON   f94c31de...  ->  f94c31de...  identical
  PM5               e3f0a203...  ->  e3f0a203...  identical
  PM5 BWM           e3f0a203...  ->  efbba2f0...  changed

Passes `make style` unmodified.

Verified on a Proxmark5 with the BWM fitted, over BLE, with the stock
client. Before, one command left the device deaf for good:

  [fpc|tcp] pm5 --> hw ping
  [+] Ping response received in 111 ms and content ( ok )
  [fpc|tcp] pm5 --> lf hitag read --ht2 --pwd -k 4D494B52
  [!] timeout while waiting for reply
  [fpc|tcp] pm5 --> hw ping
  [!] Ping response timeout
  [fpc|tcp] pm5 --> hw ping
  [!] Ping response timeout

After, the same sequence on the same device:

  [fpc|tcp] pm5 --> hw ping
  [+] Ping response received in 107 ms and content ( ok )
  [fpc|tcp] pm5 --> lf hitag read --ht2 --pwd -k 4D494B52
  [!] timeout while waiting for reply
  [fpc|tcp] pm5 --> hw ping
  [+] Ping response received in 102 ms and content ( ok )
  [fpc|tcp] pm5 --> hw ping
  [+] Ping response received in 85 ms and content ( ok )

A USB command recovers a device stuck this way, which is why the bug is
easy to miss on a bench with a cable attached: after the failing sequence
above, `hw ping` over USB answered in 1 ms and the wireless link resumed.
2026-09-15 10:36:09 -04:00
iceman1001 b65017ceaf move clocks 2026-09-01 13:32:49 +02:00
iceman1001 35c098d489 make style 2026-08-29 17:42:29 +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
Antiklesys 90b05106f8 Updates to iclass legrec and legbrute
Streamlined legbrute to remove then need for CSN and validate variables accuracy as per Iceman's suggestions.
Updated legrec (client side only) for the future arm side PR
Fixed variable overflow on the arm side for hex conversions
2024-09-18 18:10:53 +08:00
iceman1001 b0dd246d94 const and bad OR 2024-09-06 09:52:30 +02:00
iceman1001 4de7b7d6b9 style 2024-07-21 16:19:21 +02:00
Antiklesys f8fbcc2754 Bugfixes and code improvements for hf iclass legrec
1- Inlined functions related to hf iclass legrec within util.c for marginal performance gains.
2- Fixed bug preventing errors to be displayed properly and the process from interrupting on an error or on completion.
3- Fixed code indentation of the while loop in iclass.c
4- Fixed bug in the while cycle (was missing index++)
5- Improved ways to display hex results by using dbhexdump
2024-07-21 13:55:17 +08:00
Antiklesys 03adc544df Update util.c 2024-07-20 01:42:47 +08:00
Antiklesys 27cbdd3031 Update on variables and comments
Added missing definition of picopass block size in util.c
Changed some variables to full lowercase
Added comment explanation on correlation between macs and decimal values
2024-07-19 18:34:36 +08:00
Antiklesys a127a38cb6 Updated some as per iceman's comments
Made multiple changes as per iceman's comments.
Removed redundant/unused function i forgot into cmdhficlass.c
Moved conversion functions in util.c for now but haven't yet check if it's possible to reuse the current fuctions already there. Will do that in a moment.
2024-07-19 18:27:36 +08:00
iceman1001 bae6f5196f fix fct name mismatch 2024-05-14 12:42:08 +02:00
iceman1001 3f6ea0f0fc style 2024-04-22 16:35:22 +02:00
iceman1001 4304372858 tweaking felica timings to see if it gets better results 2024-04-22 10:41:28 +02:00
iceman1001 081ff216eb style 2024-01-23 15:28:50 +01:00
Martijn Plak e35385fde1 Adding processor flash memory reading, viewing and writing to file.
Works when the device is running either osimage or bootloader.

- New memory reading command in osimage and bootloader.
- Extended 'hw readmem' command with length parameter, file writing and hex viewer.
- Introduced '--dumpmem' option to proxmark3 executable to support dumping from bootloader.

Simple interactive examples:
  hw readmem -f flashdump
  hw readmem -l 1024
CLI example:
  ./pm3 --dumpmem flashdump.bin

Reading from arbitrary memory ranges can be unlocked using the 'raw' option.
2024-01-22 16:40:05 +01:00
iceman1001 70520af03b style 2023-12-14 23:38:04 +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 b4cc7c02cd Real-time LF sampling mode on armsrc 2023-11-14 01:43:20 +08:00
iceman1001 b98d518fd7 style 2022-01-06 19:41:45 +01:00
Philippe Teuwen b703bb746b Adapting license headers, WIP 2022-01-06 02:20:38 +01:00
Philippe Teuwen 5b54385347 rename globals 2021-08-21 23:08:26 +02:00
Philippe Teuwen ef586c2a41 version info also for client, still cmake to do 2020-05-20 21:11:45 +02:00
Philippe Teuwen 026707b960 arm: fix prototypes 2020-05-11 13:48:57 +02:00
iceman1001 f5bff0d4e5 style 2019-09-13 16:27:25 +02:00
iceman1001 3587aeff2a fix: LED is used as a flag, 1,2,4,8 not 1,2,3,4.. 2019-09-12 09:58:05 +02:00
Philippe Teuwen d19754567d summer restructuring:
* .h include only the strict minimum for their own parsing
  * this forces all files to include explicitment their needs and not count on far streched dependencies
  * this helps Makefile to rebuild only the minimum
  * according to this rule, most standalone .h are now gone
  * big app.h is gone
  * remove seldom __cplusplus, if c++ happens, everything will have to be done properly anyway
* all unrequired include were removed
* split common/ into common/ (client+arm) and common_arm/ (os+bootloader)
  * bring zlib to common/
  * bring stuff not really/not yet used in common back to armsrc/ or client/
  * bring liblua into client/
  * bring uart into client/
  * move some portions of code around (dbprint, protocols,...)
* rename unused files into *_disabled.[ch] to make it explicit
* rename soft Uarts between 14a, 14b and iclass, so a standalone could use several without clash
* remove PrintAndLogDevice
* move deprecated-hid-flasher from client to tools
* Makefiles
  * treat deps in armsrc/ as in client/
  * client: stop on warning (-Werror), same as for armsrc/

Tested on:

* all standalone modes
* Linux
2019-08-11 21:42:01 +02:00
Philippe Teuwen 80941ed9e1 Remove comments 2019-08-07 00:02:00 +02:00
Philippe Teuwen 9f8e63a7c8 print errors only if dbg level allows errors 2019-08-06 23:19:59 +02:00
Philippe Teuwen 650dd5855f ok it seems PMW CNTR is not reset as promised in the datasheet, let's fix this for now... 2019-08-06 23:10:02 +02:00
Philippe Teuwen 1354aec556 typos 2019-08-06 13:51:10 +02:00
Philippe Teuwen 8b3159c83d Use more defines when using main clock or master clock 2019-08-06 13:40:08 +02:00
Philippe Teuwen 2cbe43f269 clarifications and minor changes in slow clock related operations:
* SpinDelay and SpinDelayUs: now rounding applies instead of truncating
* Document maximum duration of SpinDelay/SpinDelayUs/BUTTON_CLICK/BUTTON_HELD
* Add argument check against max duration in SpinDelay/BUTTON_CLICK/BUTTON_HELD
* Document why these functions don't need to take wrapping into acount as in GetTickCountDelta
* Use >= in the spinning loops
* Clarify StartTickCount calibration operations and use masks AT91C_CKGR_MAINRDY and AT91C_RTTC_RTPRES
2019-08-06 13:09:48 +02:00
Philippe Teuwen 3b12ba2e93 replace usb_poll_validate_length() by data_available() that supports USART too 2019-06-03 00:01:08 +02:00
Philippe Teuwen fe9e1dc733 remap LEDs 2019-06-02 11:47:10 +02:00
Philippe Teuwen 4eaa2fc5aa move common util fcts to /common to avoid common files (e.g. crc) to depend on non-common files 2019-04-16 23:02:40 +02:00
Philippe Teuwen 961d929f4d changing {} style to match majority of previous style 2019-03-10 11:20:22 +01:00
Philippe Teuwen 0373696662 make style 2019-03-10 00:00:59 +01:00
Philippe Teuwen 8a7c6825b5 armsrc: fix mix of spaces & tabs 2019-03-09 20:34:41 +01:00
Philippe Teuwen 60f292b18e remove spurious spaces & tabs at end of lines 2019-03-09 08:59:13 +01:00
Chris 078196773c CHG: 'standalone bogitorun' - adapted some ledshow from Kigiv mode and increased time for user to stop pressing button after triggering the mode.. 2018-11-06 22:20:55 +01:00
iceman1001 4d8488e14b CHG: https://github.com/Proxmark/proxmark3/pull/631 from offical repo. (piwi)
CHG: textual adjustments
2018-07-28 14:25:12 +02:00
iceman1001 57df6a1a7e revert: add reflect function since its used in crc.c 2018-01-28 10:49:57 +01:00
iceman1001 cf44d04be1 add: reflect16
rem:  swapbits, reflect
2018-01-28 10:46:46 +01:00
iceman1001 ede55a1498 add: fast 8bit reversal. 2018-01-27 22:20:56 +01:00
iceman1001 3e83ff2159 CHG: '-DWITH_EMV' - fixing some compilation errors when compiling with peter fillmore's emv code. Warning a 256kb Proxmark3 device will only have 7% memory left if you enable this 2017-02-05 21:09:36 +01:00
iceman1001 53d5dc643f CHG: fiddled with the headerfiles... and makefile... Tried to make them behave nice. So it isnt a hell to add new functions from third-party (like des, aes etc)
Added a lot of #ifndef ,   extern C,
Move inside from ARMSRC -> THUMBS,  which made the compiled image smaller.. I don't know if it broke anything.
Moved MF_DBGLEVEL definitions into common.h
Moved print_result from util.c into appmain.c
Also split up some struct typedef  into header files so they could be reused in other code places.

''' danger '''  this might have broken stuff...
2017-01-25 00:33:03 +01:00
iceman1001 8be98f12e9 syntax sugar 2017-01-21 11:07:44 +01:00
iceman1001 22f4dca88c CHG: extracted some timers functionality, to get unified access to a timer/clock which counts in ticks. Moved stuff from util.c 2016-09-21 19:03:32 +02:00