MFRC522 NFC transceiver support for Write16Bytes #2027
Merged
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.
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