Skip to content

Mfrc522.ListenToCardIso14443TypeA returns incorrect ATQA #2004

@jdbruner

Description

@jdbruner

Iot.Device.Mfrc522.ListenToCardIso14443TypeA invokes PiccRequestA to perform a REQA, which returns the answer (ATQA) as a 2-byte array. ListenToCard14443TypeA converts this into a ushort. However, it treats the two bytes as a big-endian integer, whereas ISO 14443-3 specifies that the bits are sent from LSB to MSB. The MFRC522 reverses the bits within each byte but doesn't reverse the byte order. Therefore, the conversion should treat these two bytes as a little-endian integer.

Repro: listen for a Mifare Classic 1K card on an MFRC522. The expected ATQA is 0x0004 but the value 0x0400 is reported. As an example, Iot.Device.Card.Mifare.MifareCard.SetCapacity is unable to compute the card capacity when using an MFRC522, because the expected and reported ATQA values do not match.

Suggested fix: compute the ushort using

            card.Atqa = BinaryPrimitives.ReadUInt16LittleEndian(atqa);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions