Skip to content

MFRC522 - ReadUID() returns 5 bytes for a tag with a 4-byte UID #21

@brackendawson

Description

@brackendawson

Describe the bug
When reading the UID of a tag with a 4-byte UID ReadUID() returns 5 bytes.

To Reproduce
Steps to reproduce the behavior:

  1. Call ReadUID() and scan an NFC tag with a 4-byte UID.
  2. 5 bytes will be returned. Comparing to the tag's known UID, the fifth byte appears to be extraneous.

Expected behavior
4 bytes should be returned.

Platform (please complete the following information):

  • OS: Raspbian 10.9
  • Board: Gen 1 Raspberry Pi Model B
  • Device: MFRC522

Additional context
The problem appears to be here: https://github.com/periph/devices/blob/47f3fec45df8376070823f45f7624567267335a8/mfrc522/mfrc522.go#L404-414

Both antiColl() and antColll2() check the crc byte but then also return it. In the case of a 4-byte UID selectCard() then returns the whole slice including the CRC, oops.

I think in the case of a 7-byte NUID it will also be wrong, the code correctly strips byte 0 (0x88), then leaves the crc from antiColl(), then strips the crc from antiColl2(), meaning it will return 8-bytes but byte 4 will be extraneous.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions