The changefs command was using memcpy on a fixed struct layout to
serialize
SDM settings, which caused SDM offset fields to be written incorrectly.
The struct's sdm_data[8][3] array was copied contiguously, but the NTAG
424
DNA specification (AN12196) requires certain offset fields to be
conditionally
omitted based on the SDM configuration.
This resulted in:
- Plain mode: MAC offsets not written correctly
- PICC mode: MAC offsets not written correctly
- Both modes producing cmac=0000000000000000
The fix replaces the memcpy-based approach with dynamic payload building
that
conditionally includes only the required SDM offset fields in the
correct order:
- UIDOffset (only if UID option + plain mode sdmMetaRead=0xE)
- SDMReadCtrOffset (only if counter option + plain mode)
- PICCDataOffset (only if encrypted PICC mode sdmMetaRead<=0x04)
- SDMMACInputOffset (only if file read enabled)
- SDMEncOffset + SDMEncLength (only if encrypted file data enabled)
- SDMMACOffset (only if file read enabled)
- SDMReadCtrLimit (only if limit option set)
Make SHA256 output directly into the final output buffer and make the first SHA1 do the same. The second SHA1 needs an intermediate buffer as it outputs 20 bytes but we only need the first 12.
When decoding iCLASS block 7 Wiegand data, the decoder was showing
incorrect bit counts (27 for 26-bit, 36 for 35-bit, etc.) because
it wasn't stripping the sentinel bit that's added during encoding.
This fix:
- Detects when binary string has sentinel bit (leading '1' making
length one more than common formats)
- Strips the sentinel bit and recreates u96 values from corrected
binary string
- Uses corrected length for wiegand decoding
Fixes decoding for 26-bit, 35-bit, and other formats where sentinel
bit causes incorrect format detection.