nfc-tools / libnfc

Platform independent Near Field Communication (NFC) library
http://nfc-tools.org
GNU Lesser General Public License v3.0
1.72k stars 443 forks source link

pn532_i2c: How to check state and reconnect/reinit #618

Open realhik opened 4 years ago

realhik commented 4 years ago

I am using a pn532 reader connected via i2c. A door unlock software (https://github.com/rambo/nfc_lock) successfully communicates with a MIFARE Desfire ev1 tag.

However, whenever I simulate a bad i2c cable connection by shortly interrupting the power line of the NFC reader, the main loop while ( tags = freefare_get_tags(device)) { // process tags } does not discover any tags anymore.

I debugged the function but it seems that communication between the host and the pn532 still works fine.

I assume that the pn532 chip is in an uninitialised state after the interrupted line. However, calling nfc_initiator_init() again does not work.

Any ideas to

realhik commented 4 years ago

Update: It seems that the driver detects an invalid i2c protocol but then retransmit the data. Every second time the transmission spuriously succeeds. This keeps the communication "running" on a lower level but a higher level communication is no longer possible.

There should be something like a retransmit rate limit.