Skip to content

Conversation

@fill1890
Copy link
Contributor

Adds support for the NTAG21x series of PICCs, in addition to partial support for MIFARE Ultralight variants.

Major changes:

  • Fixes a bug in SELECT preventing reading UIDs longer than 4 bytes (Ultraligh tags picc_select error #73)
  • Adds picc/rc522_nxp with methods for manipulating NXP PICCs with their proprietary protocol (on top of ISO14443-3)
  • Adds additional PICC types in rc522_picc.h for Ultralight and NTAG families
  • Adds an example for the various available operations on the NTAG21x

I only have NTAG215s to test with, so I've only implemented the commands they support; however as NTAGs and Ultralights use predominately the same set of commands, this also adds at least partial support for Ultralight PICCs. A command support matrix is present at the start of picc/rc522_nxp.h for comparison across cards.

The methods in picc/rc522_nxp.h mostly provide direct access to the commands supported by the PICC (see updated README.md), as well as convenience methods for information about the memory and a method to determine the exact type of the PICC (rc522_nxp_get_type()). The example project examples/picc_nxp/ has example usage of all of these methods.

picc/rc522_nxp.h also includes commented-out stubs for commands that aren't supported on the NTAG21x. These may be useful as a starting point for future implementation, but don't currently serve any purpose.

I've incremented the version to 3.3.0 as there shouldn't be any breaking changes.

Let me know if you have any questions/want me to change anything :). Thank you!

`current_level_known_bits` in the select function was being incorrectly
calculated from the uid_index, where on each cascade level it should be
reset to 0. This resulted in an invalid command being sent to the PICC
after the first level. Setting `current_level_known_bits` to 0 on level
increment fixes this and allows Ultralight cards to be identified
correctly.

Note this issue only occurs when more than one cascade level is
required, e.g. on Ultralight cards.
- Change original UL SAK type to generic UL/NTAG
- Add additional types for UL and NTAG PICC variants:
  - `RC522_PICC_TYPE_MIFARE_UL_{,C,EV1_1,EV1_2,NANO,AES}`
  - `RC522_PICC_TYPE_NTAG2{xx,13,15,16}`
- Add messages for new types
- Add support for GET_VERSION NXP PICC command
  - Returns new `rc522_picc_version_t` struct (may be renamed)
  - New function `rc522_picc_type_from_version` to deduce type from
    version struct
- Implement checks for Ultralight C authentication support
  - Does not provide actual authentication, just checks for AUTHENTICATE
    command support. WIP: NAK should also be regarded as unsupported
- Further implement PICC type deduction per NXP AN10833
  - Adds new function `rc522_mifare_get_ul_type` that implements type
    deduction beyond the initial SAK check
- Adds new PICC driver rc522_nxp.{h,c} for Ultralight/NTAG (and more
  broadly NXP ISO14443-3 compatible PICCs)
  - Adds helper functions for retrieving page counts
  - Adds support for NXP Level 3 commands: GET_VERSION, READ, WRITE,
    FAST_READ, READ_CNT, PWD_AUTH, READ_SIG
  - Only an NTAG215 was available for testing, so other unsupported
    command not implemented
- Moves the following from `rc522_mifare` to `rc522_nxp`:
  - rc522_mifare_ul_auth_supported -> rc522_nxp_keyauth_supported
  - rc522_mifare_get_version -> rc522_nxp_get_version
  - rc522_mifare_picc_type_from_version -> rc522_nxp_type_from_version
  - rc522_mifare_get_ul_type -> rc522_nxp_get_type
- Adds constants for default PWD and PACK on password PICCs
- Adds constant for the READ command buffer size
- Adds functions to get the start and end page of user memory
- Examples for picc identification, page counts, READ, WRITE, FAST_READ, PWD_AUTH, READ_CNT,
  GET_SIG
- Memory dump example
- Minor refactor to picc_nxp.c
- Adds example output
Removes some unnecessary changes and removed definitions.
@abobija
Copy link
Owner

abobija commented Feb 27, 2025

This is awesome. Thanks a lot for huge effort. Please update with main branch and clang-format new code.

@kanflo
Copy link
Contributor

kanflo commented Mar 2, 2025

Having just found this repo for a project and noticing it lacks NDEF support, I find this PR. Excellent work! 🎉

@fill1890
Copy link
Contributor Author

fill1890 commented Mar 3, 2025

Missed a file in formatting. Should be ok now (as far as I can tell).

@fill1890
Copy link
Contributor Author

fill1890 commented Mar 3, 2025

Test compiler was tripping over the fixed-width enums. I'm not entirely sure why, given they seem to work fine for me, but given they're a C23 feature I've just removed them to avoid breaking compatibility.

@abobija abobija linked an issue Mar 4, 2025 that may be closed by this pull request
Copy link
Owner

@abobija abobija left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effort is greatly appreciated. Thanks!

@abobija abobija merged commit 956c111 into abobija:main Mar 4, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ultraligh tags picc_select error

3 participants