Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for Mifare Classic with 7-byte UIDs #2319

Merged
merged 1 commit into from
Jun 7, 2024

Conversation

jdbruner
Copy link
Contributor

@jdbruner jdbruner commented May 31, 2024

Mifare Classic cards can have either 4-byte or 7-byte UIDs (serial numbers). The existing implementation only supports cards with 4-byte UIDs (which are far more common). This PR adds support for cards with 7-byte UIDs.

There are two sets of changes in this PR:

  1. Update SetCapacity to match an ATQA of either 0x0004 (4-byte UID) or 0x0044 (7-byte UID).
  2. Change the serialization of authentication commands in Serialize to work with either length of the SerialNumber. The arguments to the AuthenticationA and AuthenticationB commands are the command byte, block number, key (6 bytes), and last four digits of the serial number (which is the entire serial number in the case of a 4-byte UID). This code was also refactored so that the same code is used for both commands (differing only in the key that is used).

Tested with Mifare Classic 1K (4-byte UID), Mifare Classic 1K (7-byte UID), and Mifare Classic 4K (4-byte UID) cards using the PN532 sample code (and a PN532 transceiver :-)).

Microsoft Reviewers: Open in CodeFlow

@jdbruner jdbruner changed the title add support for Mifare Classic with 7-byte UUIDs add support for Mifare Classic with 7-byte UIDs May 31, 2024
Copy link
Member

@Ellerbach Ellerbach left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the improvement! And thanks for confirming you've been tested it.

@Ellerbach Ellerbach merged commit e320796 into dotnet:main Jun 7, 2024
10 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jul 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants