I have similar issues when I tried to run card emulation on a PN532, both with my own code (coded from scratch for an embedded MCU) and this libnfc example (nfc-emulate-tag).
This is my setup:
A PN532 was connected to a PC running libnfc example nfc-emulate-tag.exe
A second PN532 was connected to MCU in the role of initiator. The following is executed in the MCU:
InListPassiveTarget -> to gather target information (SENS_REQ, SEL_RES, Target number...)
InDataExchange -> Pass it the Target #, FFFFFFFFFFFF as Key A, 0x60 for authenticate w/ keyA, block 0x04
This is the result using nfc-emulate-tag of libnfc v1.5.1:
------------------------------------------------------------
nfc-emulate-tag: In: 60 04 ->
Out: 12 34 -> 'Random' nonce sent by libnfc
nfc_target_receive_bytes : Parity Error
nfc_target_emulate_tag: Parity Error
InDataExchange returns status = 0x14, which is a MIFARE authentication error
CONCLUSION: This makes sense since the nonce shall be 4 bytes according to sources online. (for example: http://www.proxmark.org/documents/mifare_weakness.pdf
Therefore, I modified the code to send a 4 byte nonce: I modified nfc-emulate-tag.c around line 101:
WAS:
case 0x60: // Mifare authA
case 0x61: // Mifare authB
// Let's give back a very random nonce...
*pszOutput = 2;
pbtOutput[0] = 0x12;
pbtOutput[1] = 0x34;
IS:
case 0x60: // Mifare authA
case 0x61: // Mifare authB
// Let's give back a very random nonce...
*pszOutput = 4;
pbtOutput[0] = 0x12;
pbtOutput[1] = 0x34;
pbtOutput[2] = 0x56;
pbtOutput[3] = 0x78;
This is the result using nfc-emulate-tag of libnfc v1.5.1, bit modified to send a 4 byte nonce:
---------------------------------------------------------------------------------------------------
nfc-emulate-tag: In: 60 04 ->
Out: 12 34 56 78 -> new 4 byte nonce
In:
nfc_target_receive_bytes: Target Release
nfc_target_emulate_tag: Target Released
What I am expecting is the initiator to respond with 8 bytes, the first 4 are the response to the challenge (the original 4 byte nonce encrypted with the CRYPTO1 and KeyA). The last 4 bytes are a second nonce from the initiator
InDataExchange returns status = 0x14, which is a MIFARE authentication error, and nfc-emulate-tag.exe simply hangs waiting for a response. When I remove the PN532 target from the initiator field, I then see the 'Target Release' message from nfc-emulate-tag.exe.
Does anyone know why there is no response to the Nonce from the initiator?
Any help would be appreciated. I'm not sure the Proxmark would help me in this situation since I have seen many snoop traces from a Proxmark Online and they all show more or less the same 4 byte nonce with an 8 byte response.
Any help would be greatly appreciated.