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

Failure with PN532 #3

Open
alranel opened this issue Jul 1, 2018 · 8 comments
Open

Failure with PN532 #3

alranel opened this issue Jul 1, 2018 · 8 comments

Comments

@alranel
Copy link
Member

alranel commented Jul 1, 2018

I tried using this library with one of the popular red PN532 modules.
It didn't work. Was this library tested only with the Adafruit module?

This is the serial output using the ReadAll example (with cie.verbose = true):

Found chip PN532
Firmware ver. 1.6
PN53x initialized, waiting for a CIE card...
TIMEOUT!
TIMEOUT!
TIMEOUT!
Tag number: 1
Command (success): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Command (success): 0x00 0xA4 0x00 0x0C 0x02 0x3F 0x00
Command (success): 0x00 0xA4 0x02 0x0C 0x02 0xD0 0x03
Command (success): 0x00 0xB1 0x00 0x00 0x04 0x54 0x02 0x00 0x00 0x0E
EF_SN_ICC (12 bytes, 651 ms) [12 OCTETS STRIPPED]
We have 1302 bytes of memory left
Command (success): 0x00 0xA4 0x02 0x0C 0x02 0xD0 0x04
Command (success): 0x00 0xB1 0x00 0x00 0x04 0x54 0x02 0x00 0x00 0x03
Command (failure): 0x00 0xB1 0x00 0x00 0x04 0x54 0x02 0x00 0x01 0x03
Couldn't fetch the elementary file content
Couldn't detect a tag in the BER content
Error reading EF_DH
We have 1302 bytes of memory left
Command (failure): 0x00 0xB1 0x00 0x1D 0x04 0x54 0x02 0x00 0x21 0x06
Couldn't fetch the elementary file content
Error reading EF_ATR
We have 1302 bytes of memory left
Command (failure): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Couldn't select the IAS application
Error reading EF_ID_Servizi
We have 1302 bytes of memory left
Command (failure): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Couldn't select the IAS application
Error reading EF_Int_Kpub
We have 1318 bytes of memory left
Command (failure): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Couldn't select the IAS application
Error reading EF_Servizi_Int_Kpub
We have 1318 bytes of memory left
EF_SOD
Command (failure): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Couldn't select the IAS application
Couldn't detect a tag in the BER content
EF_SOD length was 0
We have 1318 bytes of memory left

Read complete, you can remove the card now
@BrightSoul
Copy link
Collaborator

BrightSoul commented Jul 1, 2018

Was this library tested only with the Adafruit module?

Indeed. Looking at your log, it seem a few commands get sent correctly which leads me to think the Adafruit library is working fine with this module as well. However, it fails here, when reading the second page of data from the EF_DH elementary file. It's hard to say what the problem might be since I don't own a CIE nor that module at the present time. My first guess is the NFC module is not able seek into an elementary file but I cannot tell for sure right now.

My advice is to use the low-level library from this specific vendor. The cie-PN532 project abstracts all calls to the vendor library by using the cie_Nfc base class, so a new implementation of that class should be made, following the example of the cie_Nfc_Adafruit specialized class.

In the meantime, try commenting out line #61 in the cie-ReadAll.ino sketch which will exclude reads from the EF_DH elementary file, and run it again to see whether subsequent reads work or not.

@alranel
Copy link
Member Author

alranel commented Jul 1, 2018

Thank you for the quick answer! I tried commenting line 61 and this is what I get:

Found chip PN532
Firmware ver. 1.6
PN53x initialized, waiting for a CIE card...
Tag number: 1
Command (success): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Command (success): 0x00 0xA4 0x00 0x0C 0x02 0x3F 0x00
Command (success): 0x00 0xA4 0x02 0x0C 0x02 0xD0 0x03
Command (success): 0x00 0xB1 0x00 0x00 0x04 0x54 0x02 0x00 0x00 0x0E
EF_SN_ICC (12 bytes, 640 ms) [12 OCTETS STRIPPED]
We have 1286 bytes of memory left
Command (success): 0x00 0xB1 0x00 0x1D 0x04 0x54 0x02 0x00 0x21 0x06
Command (success): 0x00 0xB1 0x00 0x1D 0x04 0x54 0x02 0x00 0x25 0x06
Command (success): 0x00 0xB1 0x00 0x1D 0x04 0x54 0x02 0x00 0x29 0x06
Command (success): 0x00 0xB1 0x00 0x1D 0x04 0x54 0x02 0x00 0x2D 0x06
Command (success): 0x00 0xB1 0x00 0x1D 0x04 0x54 0x02 0x00 0x31 0x06
Command (success): 0x00 0xB1 0x00 0x1D 0x04 0x54 0x02 0x00 0x35 0x06
Command (success): 0x00 0xB1 0x00 0x1D 0x04 0x54 0x02 0x00 0x39 0x06
Unknown error 0x00 0x00
Command (failure): 0x00 0xB1 0x00 0x1D 0x04 0x54 0x02 0x00 0x00 0x3F
Couldn't fetch the elementary file content
Error reading EF_ATR
We have 1286 bytes of memory left
Command (success): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Command (success): 0x00 0xA4 0x04 0x0C 0x06 0xA0 0x00 0x00 0x00 0x00 0x39
Command (success): 0x00 0xB1 0x00 0x01 0x04 0x54 0x02 0x00 0x00 0x0E
EF_ID_Servizi (12 bytes, 458 ms) [12 OCTETS STRIPPED]
We have 1286 bytes of memory left
Unknown error 0x03 0xAE
Command (failure): 0x00 0xB1 0x00 0x04 0x04 0x54 0x02 0x00 0x08 0xE7
Couldn't fetch the elementary file content
Error reading EF_Int_Kpub
We have 1302 bytes of memory left
Unknown error 0x03 0xAE
Command (failure): 0x00 0xB1 0x00 0x05 0x04 0x54 0x02 0x00 0x08 0xE7
Couldn't fetch the elementary file content
Error reading EF_Servizi_Int_Kpub
We have 1302 bytes of memory left
EF_SOD
Command (success): 0x00 0xB1 0x00 0x06 0x04 0x54 0x02 0x00 0x00 0x03
Command (success): 0x00 0xB1 0x00 0x06 0x04 0x54 0x02 0x00 0x01 0x03
Command (success): 0x00 0xB1 0x00 0x06 0x04 0x54 0x02 0x00 0x02 0x04
Sorry, we don't support content lengths greater than 2048
EF_SOD length was 2111
We have 1302 bytes of memory left

Read complete, you can remove the card now

(I stripped the output of EF_ID_Servizi as this is a real card)

@BrightSoul
Copy link
Collaborator

Ok, thanks. I'll do some testing as soon as I get my own CIE and see if this is reproducible on the Adafruit module as well. I've just learned it has become available in my Common.
The cie-PN532 library was tested on a specimen card, do you know of any differences with the real thing?

@alranel
Copy link
Member Author

alranel commented Jul 1, 2018

I'm not aware of any difference (maybe @fottavi is?) but I'll try to test with a fake card myself.

@fottavi
Copy link

fottavi commented Jul 4, 2018

Hello. The specimen card contain test certificates from a test Certification Authority, but for the rest they are equal by all means to real ones.

@alranel
Copy link
Member Author

alranel commented Jul 6, 2018

I tested with a specimen card and I confirm I get the same errors as above, so the issue seems related to the hardware I'm using. Since it's a pretty common alternative to the Adafruit module (and it's also quite cheaper and, last but not least, it has a smaller form factor) it would be nice to support it!

@alranel
Copy link
Member Author

alranel commented Aug 15, 2018

I did some further investigation.
When calling read_EF_DH(), readBinaryContent() is called with contentLength = 564 (I guess that's the length calculated by the BER parser). The library tries to read it in multiple chunks according to the PAGE_LENGTH constant, whose default is 228 (0xE4). However, the PN532_PACKBUFFSIZ constant in Adafruit_PN532 is set to 64. (Incidentally, that library does not perform a length check so I proposed one in adafruit/Adafruit-PN532#51)
Lowering PAGE_LENGTH to 52 makes CIE-PN532 succeed at reading all values from the card.

Then I tried to raise both PAGE_LENGTH and PN532_PACKBUFFSIZ as much as I could, and found out that the maximum working combination is {128, 139}. Above those values I either get Arduino crashes or wrong length checks. (Incidentally, 128 is 0x80 which is used for computing preambleOctets... could the two things be related?)

What do you think, @BrightSoul? A few more thoughts:

  1. Since your modified https://github.com/BrightSoul/Adafruit-PN532 library contains an unaltered PN532_PACKBUFFSIZ, how are you succeeding at all at reading EF.DH? This does not seem to be hardware-dependent. Are you sure you didn't change that value in your local copy?
  2. Where is the proper value for PN532_PACKBUFFSIZ documented? I couldn't find it in the NXP PN532 documentation, and it looks like the Adafruit module and the Elechouse one (the one I'm using) carry the same chip. Does yours show the 1.6 version number?

@alranel
Copy link
Member Author

alranel commented Aug 15, 2018

(By the way, congratulations for the code quality of CIE-PN532. It's nicely written)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants