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

change Mfrc522.ReselectTarget to use WUPA instead of REQA #2061

Merged
merged 2 commits into from
Mar 31, 2023

Conversation

jdbruner
Copy link
Contributor

@jdbruner jdbruner commented Mar 25, 2023

Mfrc522.ReselectTarget is used to reselect a card, notably after an error occurs. It does a HALT and then uses IsCardPresent to reconnect with the card, which eventually uses REQA. However, according to ISO 14443-3, if the card successfully executes a HALT then it will not respond to a REQA; instead, the PCD is required to use WUPA (wakeup). As a result, if ReselectTarget is called when the card is not in an error state, the card is non-responsive until it is taken out of range of the transceiver so that a completely new session can begin.

This PR adds an optional reselect parameter (default false) to IsCardPresent and also adds an optional commandCode parameter to the private function PiccRequestA to specify which command to send to the card. ReselectTarget uses this to request reselection with WUPA.

With this change, it is now possible to halt and wake up cards. Calling ReselectTarget (typically using something like MifareCard.ReselectCard) on a card that is not in error state no longer puts the card in a non-responsive state.

Pn532.ReselectTarget already uses WUPA., and Pn5180.ReselectTarget is not implemented for Type A.

Microsoft Reviewers: Open in CodeFlow

@ghost ghost added the area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio label Mar 25, 2023
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 as well. Thanks for the heavy testing here.

@jdbruner
Copy link
Contributor Author

What do I need to do in order to resolve the API compatibility errors (because of the new optional parameter to IsCardPresent)?

/// <returns>true if there is a card, else false.</returns>
public bool IsCardPresent(byte[] atqa)
public bool IsCardPresent(byte[] atqa, bool reselect = false)
Copy link
Member

Choose a reason for hiding this comment

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

NIT: In order to not be binary breaking, any reason why we shouldn't just add new overloads as opposed to using default parameters?

@joperezr
Copy link
Member

What do I need to do in order to resolve the API compatibility errors

You just rerun the pack command locally and pass in the property /p:ApiCompatGenerateSuppressionFile=true so that the errors get baselined. I ran that locally so I'll just take the liberty to push those changes here. That said, I did ask the question above to consider just adding a new overload instead so as to not be binary breaking. @jdbruner if you end up deciding to do that, please just revert the change that I'm about to push as it won't be needed any longer.

@jdbruner
Copy link
Contributor Author

Thanks. I thought about creating an overload, but from a documentation perspective I think it is easier to understand the optional argument than the overloaded alternatives.

@krwq
Copy link
Member

krwq commented Mar 30, 2023

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@joperezr
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Ellerbach Ellerbach merged commit 387ee20 into dotnet:main Mar 31, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
This pull request was closed.
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