Closed wojtekka closed 5 years ago
I think your information is a bit outdated.
As reference use: https://www.nxp.com/docs/en/application-note/AN10833.pdf Rev. 3.6—11 July 2016
There are some differences like:
3.2 Coding of Select Acknowledge (SAK) [...] UID not complete 00000100
I'm referring to ISO/IEC standard, you're referring to an application note. Sure, NXP is not just some random manufacturer but in case of "UID not complete" it looks like an oversimplification.
Anyway, after looking at PICC_Select
method, I see that:
0x04
when checking if UID is complete,uid->sak
will not be set if UID is not complete, so PICC_GetType
should never see this bit after all.If you want me to leave the original PICC_TYPE_NOT_COMPLETE
condition, I'd be happy to do that. That was just a "by-the-way" cleanup attempt. I'm more interested in proper handling of some the ISO 14443-4 cards I have.
uid->sak will not be set if UID is not complete, so PICC_GetType should never see this bit after all.
Correct, but variable uid
is public, so it could be set.
Sure, NXP is not just some random manufacturer but in case of "UID not complete" it looks like an oversimplification.
Could be that they simplified their application notes, but it is documented. Please add iso standard + year + chapter to your implementation, so we can avoid that it is changed back.
Some other notes:
PICC_TYPE_ISO_14443_4
and PICC_TYPE_ISO_18092
should be done after the switch
because those checks are more generalI added excerpts from ISO/IEC 14443-3:2016 and ISO/IEC 18092:2013 in the comments. I also modified MFRC522Extended::PICC_GetType()
to use MFRC522::PICC_GetType()
to avoid redundancy.
There's annex B in ISO/IEC 18092:2013 which describes SAK algorithm:
That's why I'm checking those two bits before detecting MIFARE type. Note that none of the MIFARE SAKs described in AN10833 have bits 6 and 7 set except those that actually are ISO/IEC 14443-4 compliant. That's why MFRC522Extended::PICC_GetType()
has an additional condition for MIFARE DESFire.
As for checking if bit 3 is 0, the first condition checks if it's 1 and then returns so the rest of the method is executed only if bit 3 is 0. I can change it to if/else if it increases readability.
Information about SAK coding in both ISO/IEC 14443-3 and ISO/IEC 18092 shows that most of the bits are "don't care", so the value should not be compared as whole but bitmasked instead: