Commit Graph
23209 Commits
Author SHA1 Message Date
iceman1001 054fae4ac1 fixed the spinner and download reporting 2026-09-12 18:30:45 +02:00
Iceman af0b0095ca Merge pull request #3621 from nieldk/master
Improve reset when upgrade/change name BWM
2026-09-12 22:18:21 +07:00
Niel Nielsen 028aae180d Add cmdbwm.c to CMakeLists.txt
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 17:07:50 +02:00
Niel Nielsen 2c779f337f Update cmdbwm.c
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 16:51:53 +02:00
Niel Nielsen 3bdef8b23b Add files via upload
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 16:48:51 +02:00
Niel Nielsen 0a0dd87224 Remove unused BWM command functions
Removed unused functions related to BWM commands and OTA process.

Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 16:48:08 +02:00
Niel Nielsen bd24a6197d Fix Makefile to include dependency files correctly
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 16:47:03 +02:00
Niel Nielsen b808f61c1f Add cmdbwm.c to CMakeLists and include CPack
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 16:46:35 +02:00
Niel Nielsen 6c34b6993c Refactor BWM firmware update and reset logic
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 16:33:14 +02:00
iceman1001andClaude Opus 5 (1M context) 05137e825a hold the spiffs file open across an upload
SPIFFS has no directory.  SPIFFS_open() by name walks the object lookup page of
every block and reads the header of each index page it meets to strcmp the name,
so reopening per packet makes an upload cost packets x filesystem size.  On a 2MB
part one open reads about 120KB of flash - storing a 512KB file spent 16MB of
reads finding the same file 131 times over, and 249MB back when a packet was one
256 byte flash page.

append_to_spiffs() now keeps the descriptor when the next packet names the same
file.  Everything else calls spiffs_close_cached() on entry, so a held descriptor
is closed, and its writes flushed, before any other operation can look at the
file - all 15 direct SPIFFS_* call sites in this file are covered.  No protocol
change: the CMD_SPIFFS_UNMOUNT the client already sends at the end of an upload
closes it, as does any other SPIFFS command.  rdv40_spiffs_unmount() closes
before SPIFFS_unmount() since descriptors do not survive a mount, and the close
checks the mount state so a dead handle is dropped rather than passed on.

Flash reads to store a file, measured on a host build of this filesystem:

  2MB fs, 512KB file, 4029 byte packets   16302 KB -> 371 KB
  2MB fs, 512KB file,  256 byte packets  249415 KB -> 914 KB
  2MB fs, 256KB file, 4029 byte packets    7834 KB -> 313 KB
  256KB fs, 80KB file, 589 byte packets    1483 KB ->  82 KB

Written bytes are unchanged; only the searching went away.

Verified on the host against an order sensitive pattern - content byte identical,
size right, SPIFFS_check clean - both for a straight upload and for one with a
stat and an fsinfo landing mid transfer, which is the case that catches a missed
invalidation.  Then on hardware: 80KB uploaded, 'mem spiffs tree' in between to
force a flush, downloaded again, byte identical.

Co-Authored-By: Claude Opus 5 (1M context)
2026-09-12 15:54:40 +02:00
iceman1001 e87343dbef add missing ManchesterDecoding_Thinfilm decl 2026-09-12 15:29:23 +02:00
iceman1001 a878043061 fix missing appmain changes 2026-09-12 15:24:46 +02:00
iceman1001 cb75a05553 text 2026-09-12 15:14:13 +02:00
iceman1001 f57da9c85d missing files 2026-09-12 15:10:36 +02:00
iceman1001andClaude Opus 5 (1M context) 696b8357b6 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)
2026-09-12 15:09:53 +02:00
iceman1001andClaude Opus 5 (1M context) 9a8e179266 fix spiffs downloads >= 64K, and stop losing flash errors
CMD_SPIFFS_DOWNLOAD read the whole file into BigBuf first.  BigBuf_calloc()
takes a uint16_t while the size is a uint32_t, so a 64K file allocated zero
bytes and anything larger wrapped to a short buffer the file was then read
straight past the end of.  rdv40_spiffs_read_stream() opens the file once and
hands out one frame at a time, so the size never reaches the allocator, and the
SPIFFS path now honours start_index.  Verified with an 80K round trip: upload,
download, byte identical.

The same BigBuf_calloc(filesize) wrap was in copy_in_spiffs(); it now copies in
SPIFFS_WRITE_CHUNK_SIZE chunks.

Separately, every flash failure was invisible.  SPIFFS_CHECK_RES() only treats a
negative result as an error and the HAL hooks returned 128/129/130, so SPIFFS
saw success.  The erase path was worst: Flash_Erase4k() only reports that the
command was sent, both Flash_CheckBusy() results were discarded, and
'return (SPIFFS_OK == erased)' yields 1 on failure.  A flash dump from a device
that hit this showed one block written without being erased - its object index
header held '0x14000 & 0x10000', and the filename ANDed away to empty.  Erases
are now read back and retried, and the HAL returns real SPIFFS error codes.

Flash_Write() returned len unconditionally even after a rejected page, which
also defeated the 'res == payload->len' check in CMD_FLASHMEM_WRITE.

Feedback, so none of this is silent again: CMD_SPIFFS_WRITE answers with the
SPIFFS result, the client aborts on the first refusal and names the byte it
stopped at, dl_it() checks the terminator status, and both transfer directions
print inline progress.

Co-Authored-By: Claude Opus 5 (1M context)
2026-09-12 14:58:08 +02:00
iceman1001andClaude Opus 5 (1M context) a967560335 hf thinfilm sim - shorter frame gap
The inter frame delay was 3600us for a 128 bit payload and 2400us for 256 bit,
sized so that either one holds a constant 4.8ms repeat period.  That is the wrong
target.  A Kovio tag is never transacted with - the reader captures it during a
poll slot and hands the bytes up as an activation, see
nfa_dm_disc_handle_kovio_activation() in libnfc-nci, which reads the barcode
straight out of rf_tech_param.param.pk.uid - so the only thing that matters is how often a frame is on the air.

Measured repeat period before today was 8.66ms, ie 14% duty cycle.  A fixed 500us
gap takes a 128 bit payload to roughly 2.2ms.  The gap cannot go to zero, a reader
needs unmodulated carrier to find the frame start and our own demod wants three
quiet bytes, but 500us is an order of magnitude clear of that.

Also drop the 'not correct' caveat from 'hf thinfilm list', the sim side traces
properly now.

Tested on RDV4 against an Android reader.  Builds clean for PM3RDV4 and PM5.

Co-Authored-By: Claude Opus 5 (1M context)
2026-09-12 14:17:13 +02:00
Iceman a7c6116258 Merge pull request #3620 from nieldk/master
Add BWM set BLE name
2026-09-12 19:03:24 +07:00
iceman1001andClaude Opus 5 (1M context) 91f5f7e9a2 fix hf thinfilm sim
SimulateThinFilm() set the SSC up with FPGA_MAJOR_MODE_HF_READER but wrote a conf
word for FPGA_MAJOR_MODE_HF_ISO14443A | TAGSIM_MOD.  On the HF bitstream
FpgaIs16BitMsbMode() picks 16 bit frames for HF_READER, so every 8 bit SEC_D /
SEC_E went on air as 0x00 followed by the symbol, ie half the symbol rate with an
unmodulated gap before each one.  No reader decodes that and nothing errors.

Broken since e144c793f (2020-07-02) added the argument and the 16 bit branch.
thinfilm.c has passed HF_READER since 2019, when FpgaSetupSsc() took no argument
and was always 8 bit.  Every other tag sim in the tree passes HF_SIMULATOR or
HF_ISO14443A and was unaffected.

The send loop also called ReadReaderField() between every frame.  That is
AdcRssiAvg(), 32 conversions each paying a 42.7us ADC startup and a 40us sample
and hold, about 3.8ms - more than the deliberate inter frame delay sitting next
to it.  Measured repeat period was 8.66ms against the 4.8ms the delays were
written for, ie 14% duty cycle.  Poll with 4 samples, keep 32 for the one off
baseline.

The sim now enables tracing and logs each beamed frame, so 'hf thinfilm list'
works on the sim side too, and the coded buffer hexdump is behind DBG_DEBUG
instead of printing 8 lines every run.  It also read 16 bytes per line
unconditionally, so an odd length payload over read the buffer.

Tested on RDV4.  Builds clean for PM3RDV4 and PM5.

Co-Authored-By: Claude Opus 5 (1M context)
2026-09-12 13:58:39 +02:00
iceman1001 f48250d51f text 2026-09-12 13:47:54 +02:00
Niel Nielsen 443b2d8fc8 Document 'hw bwm name' command for BLE name management
Added documentation for the 'hw bwm name' command, detailing how to get and set the BLE advertising name, including usage examples and notes on behavior during name changes.

Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 13:45:14 +02:00
Niel Nielsen e2cefcff3a Refine OTA command and timeout configurations
Updated OTA command definitions and timeout settings.

Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 13:29:52 +02:00
Niel Nielsen 423ede5d29 Update print statement from 'Hello' to 'Goodbye'
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 13:29:30 +02:00
Niel Nielsen 7046f43bfb Refactor BWM command handling and improve help messages
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 13:28:42 +02:00
Niel Nielsen 407d9d7474 Add BLE name handling for GET and SET commands
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 13:27:34 +02:00
Niel Nielsen 945619c2d5 Add BLE name command definitions to pm3_cmd.h
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 13:27:00 +02:00
Niel Nielsen 9d587e3dcc Update OTA command definitions and BLE functions
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 13:20:53 +02:00
Niel Nielsen 2b98c126a7 Update print statement from 'Hello' to 'Goodbye'
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 13:20:24 +02:00
Niel Nielsen 815d03baa3 Refactor BWM command handling with CLI parser
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 13:17:53 +02:00
iceman1001 812722ed81 fix overflow 2026-09-12 12:49:17 +02:00
iceman1001 3ea9d885cb fix realloc patterns 2026-09-12 12:42:02 +02:00
iceman1001 7285f1158d cleaner return value 2026-09-12 12:38:05 +02:00
iceman1001 47507a1d21 better string handling in the client in felica, hitagU, hitagS 2026-09-12 12:28:28 +02:00
iceman1001 58580c690f add a str_append fct. To handle some string manipulation issues in the client 2026-09-12 12:26:06 +02:00
iceman1001 10dafd8048 fix a hitagu overflow in cmdtrace.c 2026-09-12 11:56:10 +02:00
iceman1001 df68cf72e0 hf mf: match the isOK status locals to reply_ng() 2026-09-12 11:47:03 +02:00
iceman1001andClaude Opus 5 (1M context) 50a2b0ca37 hf mf autopwn: recover the crypto1 session when a read is denied
A read the card NAKs aborts the crypto1 session, so after the first
denied block every later read in that sector came back with len 0 and
the retry loop spun on it. One unreadable block cost the whole sector,
and the dump only recovered when the next sector did a fresh select.

MifareECardLoad also only fell back to key B when the *auth* failed,
never when the *read* was denied, so a sector whose access conditions
allow a read with B but not with A was lost even though both keys were
known. That is the gap between this and the client side 'hf mf dump',
which picks the key per block.

Re-select and re-authenticate after a NAK, and retry the block with the
other key first. If it reads, stay on that key for the rest of the
sector; if it does not, re-auth with the original key so the remaining
blocks still read instead of collapsing. The backdoor key path has no
counterpart key to swap to, so it only clears bd_authenticated to force
a re-select on the next sector.

On an MFC EV1 with two sectors that deny key A reads, this takes the
dump from PARTIAL with 96 spurious len-0 errors to complete on the first
pass.

Co-Authored-By: Claude Opus 5 (1M context)
2026-09-12 11:24:32 +02:00
iceman1001 667b62f405 make codeql happy 2026-09-12 11:14:09 +02:00
iceman1001 03fed51af5 fix isOK size 2026-09-12 11:10:38 +02:00
Iceman 780081a2e9 Merge pull request #3619 from nieldk/master
pm5: fix antenna RGB staying dark on battery cold boot
2026-09-12 16:01:11 +07:00
Niel Nielsen 711b6ebcd6 Merge branch 'RfidResearchGroup:master' into master 2026-09-12 10:44:42 +02:00
iceman1001andClaude Opus 5 (1M context) 6341f40b4c hf mf hardnested: fix the nonce reply length, 9 bytes per pair not 4 per nonce
Thanks @TheArchitect0880 for pointing it out and suggested a first fix.

MifareAcquireEncryptedNonces packs two 4 byte encrypted nonces plus one
byte holding both their encrypted parity nibbles into every entry, but
the reply declared num_nonces * 4 bytes. The client walks that buffer 9
bytes at a time, so on RDV4 it read 612 bytes out of a 544 byte payload
and handed roughly 15 of every 136 nonces to add_nonce() from stale
packet buffer content. Those fake nonces went into the .bin nonce file
too.

Count pairs instead of bytes. num_nonces now reports whole pairs only,
so a button abort or a static nonce bailout part way through a pair
drops the dangling nonce rather than shipping a half built entry whose
parity nibble was never filled in.

MFC_NONCE_PAIR_SIZE and MFC_MAX_NONCE_PAIRS document the layout next to
mf_nonces_resp_t so the 9 vs 4 confusion cannot come back, and the
client now refuses a reply too short for the nonce count it carries.

Both acquisition functions collect straight into the reply buffer rather
than a second PM3_CMD_DATA_SIZE stack array, which halves the stack used
per call. MifareAcquireNonces also returned isOK = 2 on button press,
which is not a PM3_* status; that is PM3_EOPABORTED now.

Co-Authored-By: Claude Opus 5 (1M context)
2026-09-12 10:44:00 +02:00
Niel Nielsen c6339ad99c Change RgbLedSet return type to bool
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 10:35:40 +02:00
Niel Nielsen 50c189ed0a Change RgbLedSet to return bool for success status
Modify RgbLedSet to return success status and handle cold boot NAK.

Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 10:35:00 +02:00
Niel Nielsen ac7a3f3c5a Improve RGB LED state handling on power source change
Add acknowledgment check for RGB LED state change.

Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-12 10:31:32 +02:00
Iceman 5ca15e4587 Merge pull request #3616 from mfcarroll/t55xx-psk-trim-graphbuffer
lf t55xx detect: save and restore the graph buffer through the shared helpers
2026-09-11 22:53:21 +07:00
iceman1001 7fb520ce18 text 2026-09-11 15:17:52 +02:00
iceman1001andClaude Opus 5 (1M context) 67c121f554 hf mfdes detect: sweep all key numbers, and count errors per key type
errcount was declared before the key type loop and only reset by a
non -11 result, so eleven scattered card errors during the DES pass left
the AES pass to break on its first error without trying a key.  Count
per key type instead.

With no -n, detect only ever looked at key 0.  Sweep the key numbers the
application declares (low nibble of the key settings) instead, falling
back to 0x00..0x0D when the settings are unreadable.  All keys in an
application share an algo, so the first key number that succeeds narrows
keytypes[] for the rest.  --save now stores the first key found rather
than whatever dctx was left holding, and a lost card aborts the sweep.

-n <num> behaves exactly as before.

Co-Authored-By: Claude Opus 5 (1M context)
2026-09-11 15:15:36 +02:00
iceman1001andClaude Opus 5 (1M context) e0543bd612 hf mfdes detect: probe for LRP, and use the DESFire dictionary
Two things stopped 'detect' finding keys it should have found.

An AES application and an LRP application report the same key settings
byte, so a card in LRP mode was only caught when the settings happened to
be unreadable and the auth-command fallback ran.  Probe with
AuthenticateLRPFirst whenever --schann was not given, then re-select.

With no -f, candidates came from g_mifare_plus_default_keys, which is 26
entries of 16 byte AES.  For DES that meant authenticating with the first
half of an AES key, and for 3K3DES it fabricated 24 bytes as
key[0..15] + key[0..7].  Default to the bundled mfdes_default_keys
dictionary instead: 7 DES, 47 2TDEA/AES and 4 real 3K3DES keys.

Co-Authored-By: Claude Opus 5 (1M context)
2026-09-11 12:38:16 +02:00
Matthew CarrollandClaude Opus 5 e810245caa lf t55xx detect: save and restore the graph buffer through the shared helpers
The psk antenna-settle trim open-coded the save/restore pair: save_bufferS32
plus g_GridOffset on the way in, and restore_bufferS32's return assigned to
g_GraphTraceLen on the way out. graph.c now has save_graphbuffer and
restore_graphbuffer, which hold contents, length and grid offset together, so
call those and drop the local copy of the length contract.

No behaviour change. `lf t55xx detect -1` on the in-tree psk traces leaves the
graph at 20000 samples before and after.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 02:20:10 -07:00