nfc-tools / libnfc

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

get a "Too small reply" error instead a "Parameter error" with an acr122 (touchatag) #251

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. plug an acr122 (touchatag)
2. put a Mifare Ultraligh C on the reader (it was not a deliberate action to 
put a Ultralight, I thought it was a desfire)
3. run the command pn53x-tamashell with the extra parameter LIBNFC_LOG_LEVEL=3
4. send the polling instruction to the tag (4a  01  00)
5. send a Mifare Desfire instruction to select the root application (40 01 90 
5a 00 00 03 00 00 00 00)

What is the expected output? What do you see instead?
I was expecting a "Parameter error" and I got a "Too small reply error".  So I 
enabled the debug_mode to see the details.  The libnfc.driver.acr122_usb module 
receives an error code 63 7f from the reader and it manages like a 61 7f code.  
So It tries to retrieve 7f bytes of data from the reader but there is no one.  
Then the driver print "Too small reply error".

I joined bellow the output of the tamashell in debug mode.  

What version of the product are you using? On what operating system?
libnfc version: libnfc 1.7.0-rc7
operating system version: openSUSE 12.2 Mantis (i586)

Please provide any additional information below.
Tamashell output:
> 40 01 90 5a 00 00 03 00 00 00 00
Tx: 40  01  90  5a  00  00  03  00  00  00  00  
debug   libnfc.chip.pn53x   InDataExchange
debug   libnfc.chip.pn53x   No timeout
debug   libnfc.driver.acr122_usb    TX: 6f 11 00 00 00 00 00 00 00 00 ff 00 00 00 0c 
d4 40 01 90 5a 00 00 03 00 00 00 00 
debug   libnfc.driver.acr122_usb    RX: 80 02 00 00 00 00 00 00 00 00 63 7f 
debug   libnfc.driver.acr122_usb    TX: 6f 05 00 00 00 00 00 00 00 00 ff c0 00 00 7f 
debug   libnfc.driver.acr122_usb    RX: 80 02 00 00 00 00 00 00 00 00 63 00 
error   libnfc.driver.acr122_usb    Too small reply
Rx: Input / Output Error

Original issue reported on code.google.com by djo...@gmail.com on 4 Jun 2013 at 2:45

GoogleCodeExporter commented 9 years ago
This issue was updated by revision af7eef0c54b1.

The driver now check that Status Word (SW1) is equals to 0x61 (more data 
available) before using SW2 as length.
If SW is not as expected, it show SW1 and SW2.

Original comment by romu...@libnfc.org on 13 Jun 2013 at 1:57

GoogleCodeExporter commented 9 years ago
Thanks for reporting.

This issue is not fixed but libnfc does now handle SW and display a better 
message.

Original comment by romu...@libnfc.org on 13 Jun 2013 at 1:59

GoogleCodeExporter commented 9 years ago
I'm not sure we can achieve better error handling

In this example a wrong command was sent to a ULC

The ULC replies with a 0x0 (4bits) = "any other error (NAK)"
But with a MFC, the card stays silent in case of wrong command.

Then the PN532 does not send back those 4 bits (or no response in case of MFC) 
but it replies to the reader microcontroller a standard error frame 
(0000FF01FF7F8100) to inform the controller that it has detected an error at 
the application level.

The controller encapsulates this 7F into a SW=637F as it is using pseudo-APDUs.
(63xx errors are ISO7861-4 warnings)

So we just know an error occurred but we cannot know more.

Now maybe it's better to send something like "PN532 has detected an error at 
the application level" rather than "Unexpected SW".
I'll capture specifically the 637F and leave Unexpected SW for the other cases 
if any.

Original comment by yob...@gmail.com on 13 Jun 2013 at 6:48

GoogleCodeExporter commented 9 years ago
This issue was closed by revision f0471ebc894d

Original comment by yob...@gmail.com on 13 Jun 2013 at 7:02