Repository navigation
feat: NTAG 424 DNA plain file operations - #18
Merged
Merged
Conversation
Add Cards/NTAG424 with NTAG 424 DNA native commands in CommMode.Plain: - NTAG424Commands.getFileSettings(fileID:) sends GetFileSettings (F5h) and parses the response strictly into NTAG424FileSettings: file type, file option / communication mode, access-right nibbles, 24-bit file size and, when SDM is enabled, SDMOptions, SDMAccessRights and every offset the options and access rights make present. Truncated responses, trailing bytes (such as a response MAC), non-StandardData files and a reserved SDMMetaRead value throw invalidResponse. - NTAG424Commands.writeDataPlain(fileID:offset:data:chunkSize:) sends the native WriteData 8Dh (not the DESFire 3Dh) with 3-byte little-endian offset and length, split into short-APDU chunks. - Facades CoreExtendedNFC.getNTAG424FileSettings(fileID:transport:) and writeNTAG424DataPlain(fileID:offset:data:chunkSize:transport:). SDMAccessRights is decoded as SDMMetaRead bits 15-12, SDMFileRead 11-8, RFU 7-4, SDMCtrRet 3-0, checked against the NXP AN12196 GetFileSettings (Tables 7, 10/11, 18) and plain WriteData (Table 24) vectors in Vectors/NTAG424VectorTests.swift. ChangeFileSettings / SDM provisioning, CommMode.MAC / Full and EV2 command counters are out of scope. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review findings checked against NT4H2421Gx / NT4H2421Tx Rev. 3.0: - Default WriteData chunk is now 111 bytes so each command fits one 128-byte ISO/IEC 14443-4 frame (ATS T0 77h, CID supported). The datasheet only guarantees tearing protection within one frame (§10.8.2, §8.5); the old 128-byte default produced 141-byte APDUs that the reader chains. The 248-byte maximum (Table 81) is unchanged. - GetFileSettings parses TTStatusOffset, present on NTAG 424 DNA TT when SDMOptions bit 3 is set, between PICCDataOffset and SDMMACInputOffset (NT4H2421Tx Table 73). Such responses used to be rejected. - SDMAccessRights gains counterRetrievalCondition; doc comments note that SDMReadCtrOffset FFFFFFh means no counter mirroring and that SDMFileRead Eh is RFU but still makes the MAC offsets present. - The writeNTAG424DataPlain doc now states the real precondition: without authentication the Write or ReadWrite access condition must be Eh; the file's CommMode only applies inside an authenticated session. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NTAG 424 DNA shares DESFire's ATQA 0344h / SAK 20h, so iOS can report it as a DESFire tag. It has no GetApplicationIDs (NT4H2421Gx Table 22) and answers 91 1C (Table 23), which made dumpCard fail. When that happens and GetVersion reports hardware type 04h (NTAG, Table 54) the tag is now dumped through the Type 4 path; any other chip still reports the error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #14
Summary
New
Cards/NTAG424module for NTAG 424 DNA native file operations in CommMode.Plain, over the ISO 7816 wrapped transport (90 CMD 00 00 Lc data 00) with the NDEF application selected.NTAG424Commands.getFileSettings(fileID:)— GetFileSettingsF5h, parsed strictly intoNTAG424FileSettings:AccessCondition), 24-bit file size.SDMOptions,SDMAccessRights(SDMMetaRead bits 15-12, SDMFileRead 11-8, RFU 7-4, SDMCtrRet 3-0) and the conditional UID / SDMReadCtr / PICCData / TTStatus (NTAG 424 DNA TT) / SDMMACInput / SDMENC offset + length / SDMMAC / SDMReadCtrLimit fields.invalidResponse.NTAG424Commands.writeDataPlain(fileID:offset:data:chunkSize:)— native WriteData8Dh(not DESFire3Dh), 3-byte little-endian offset and length, split into chunks (default 111 bytes so each command fits one tearing-protected 128-byte ISO 14443-4 frame; max 248, the datasheet limit). Arguments are validated before anything is sent; the first non-9100status stops the write.CoreExtendedNFC.getNTAG424FileSettings(fileID:transport:)andCoreExtendedNFC.writeNTAG424DataPlain(fileID:offset:data:chunkSize:transport:).NTAG424Commandsfollows the access policy (open class,@unchecked Sendable, immutable state,open class funcpayload hook).Out of scope: ChangeFileSettings / SDM provisioning, CommMode.MAC / Full, EV2 command counters and response-MAC verification.
Tests
NTAG424Tests.swift: MockTransport APDU framing, 24-bit LE ranges, chunking, status mapping, argument validation, every truncation, trailing bytes, reserved values.Vectors/NTAG424VectorTests.swift: NXP AN12196 published vectors — GetFileSettings responses from Tables 7 and 18, the illustrative Table 10 response (rejected as truncated against its own SDMAccessRights), and the plain CC WriteData C-APDU from Table 24.Vectors/NTAG424VectorTests.swiftalso covers the NT4H2421Tx TTStatusOffset layout.DESFireDumpTests.swift: an NTAG 424 DNA reported as DESFire (GetApplicationIDs →91 1C, GetVersion hardware type04h, AN12196 Table 12 transcript) is dumped as a Type 4 tag; other chips still report the error.Verified on the iOS Simulator: package tests (1081 tests, 72 suites) pass, Example app builds.
Review
Three review rounds, each finding fixed only after a test reproduced it:
counterRetrievalCondition.Not validated on hardware yet; the module is experimental.
Docs
Also
DESFireVersionInfo.ntagHardwareType.CHANGELOG (Unreleased), README support table and tree,
docs/api/card-commands.html,docs/api/core.html,docs/architecture.html,docs/index.html,docs/research/references.html.🤖 Generated with Claude Code