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

MFRC522 NFC transceiver support for Write16Bytes #2027

Merged
merged 1 commit into from
Feb 12, 2023

Conversation

jdbruner
Copy link
Contributor

@jdbruner jdbruner commented Feb 4, 2023

Mifare's Write16Bytes command, which is used by Mifare Classic and Mifare Ultralight (where it is called "compatibility write") requires two writes to the card. The first one transfers the block number, and the second contains the data to be written. The Mfrc522 transceiver was not doing this, so writes to a Mifare Classic card always failed. Changed the Transceive function to treat Write16Bytes the same as counter increment, decrement, and restore (which also require two writes to the card).

In addition to renaming TwoStepsIncDecRestore to TwoStepsWrite16IncDecRestore, there were two issues in this method. First, the calculation of the CRC for the second transfer was incorrect. Second, it appears that the Mfrc522 actually returns a single byte response from the second transfer (which looks like the ACK/NAK), but dataFromCard.Length is 0, so SendAndReceiveData will return an error even though the write succeeded. Actual errors are already detected separately, so the simplest change is to pass NULL rather than dataFromCard. This makes dataFromCard unused, so it is removed from the method interface.

Microsoft Reviewers: Open in CodeFlow

Mifare WRite16Bytes, which is used by Mifare Classic and Mifare Ultralight (where it is called
"compatibility write") requires two writes to the card. The first one transfers the
block number, and the second contains the data to be written. Changed the Transceive
function to handle Write16Bytes the same as counter increment, decrement, and restore
(which also require two writes to the card).
@ghost ghost added the area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio label Feb 4, 2023
@dnfadmin
Copy link

dnfadmin commented Feb 4, 2023

CLA assistant check
All CLA requirements met.

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.

Thanks for the fix, looks good to me.

@pgrawehr pgrawehr merged commit 0716f17 into dotnet:main Feb 12, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants