nfc-emulate-ndef now using easy framing & fix timing issues
This commit is contained in:
parent
2024e5f904
commit
d75e25d29d
2 changed files with 38 additions and 31 deletions
|
@ -36,8 +36,6 @@
|
||||||
|
|
||||||
#include <nfc/nfc-messages.h>
|
#include <nfc/nfc-messages.h>
|
||||||
#include "nfc-utils.h"
|
#include "nfc-utils.h"
|
||||||
// FIXME doesn't use a pn53x specific function, use libnfc's API
|
|
||||||
#include "chips/pn53x.h"
|
|
||||||
|
|
||||||
#define MAX_FRAME_LEN 264
|
#define MAX_FRAME_LEN 264
|
||||||
|
|
||||||
|
@ -48,8 +46,7 @@ static bool quiet_output = false;
|
||||||
|
|
||||||
#define SYMBOL_PARAM_fISO14443_4_PICC 0x20
|
#define SYMBOL_PARAM_fISO14443_4_PICC 0x20
|
||||||
|
|
||||||
bool
|
bool send_bytes (const byte_t * pbtTx, const size_t szTxLen)
|
||||||
transmit_bytes (const byte_t * pbtTx, const size_t szTxLen)
|
|
||||||
{
|
{
|
||||||
// Show transmitted command
|
// Show transmitted command
|
||||||
if (!quiet_output) {
|
if (!quiet_output) {
|
||||||
|
@ -60,12 +57,17 @@ transmit_bytes (const byte_t * pbtTx, const size_t szTxLen)
|
||||||
// Transmit the command bytes
|
// Transmit the command bytes
|
||||||
if (!nfc_target_send_bytes(pnd, pbtTx, szTxLen)) {
|
if (!nfc_target_send_bytes(pnd, pbtTx, szTxLen)) {
|
||||||
nfc_perror (pnd, "nfc_target_send_bytes");
|
nfc_perror (pnd, "nfc_target_send_bytes");
|
||||||
return false;
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
// Succesful transfer
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool receive_bytes (void)
|
||||||
|
{
|
||||||
if (!nfc_target_receive_bytes(pnd,abtRx,&szRxLen)) {
|
if (!nfc_target_receive_bytes(pnd,abtRx,&szRxLen)) {
|
||||||
nfc_perror (pnd, "nfc_target_receive_bytes");
|
nfc_perror (pnd, "nfc_target_receive_bytes");
|
||||||
return false;
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show received answer
|
// Show received answer
|
||||||
|
@ -100,9 +102,6 @@ main (int argc, char *argv[])
|
||||||
.nti.nai.szAtsLen = 0,
|
.nti.nai.szAtsLen = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME doesn't use a pn53x specific function, use libnfc's API
|
|
||||||
pn53x_set_parameters(pnd,SYMBOL_PARAM_fISO14443_4_PICC);
|
|
||||||
|
|
||||||
if (!nfc_target_init (pnd, NTM_ISO14443_4_PICC, nt, abtRx, &szRxLen)) {
|
if (!nfc_target_init (pnd, NTM_ISO14443_4_PICC, nt, abtRx, &szRxLen)) {
|
||||||
nfc_perror (pnd, "nfc_target_init");
|
nfc_perror (pnd, "nfc_target_init");
|
||||||
ERR("Could not come out of auto-emulation, no command was received");
|
ERR("Could not come out of auto-emulation, no command was received");
|
||||||
|
@ -117,35 +116,41 @@ main (int argc, char *argv[])
|
||||||
//Receiving data: e0 40
|
//Receiving data: e0 40
|
||||||
//= RATS, FSD=48
|
//= RATS, FSD=48
|
||||||
//Actually PN532 already sent back the ATS so nothing to send now
|
//Actually PN532 already sent back the ATS so nothing to send now
|
||||||
transmit_bytes((const byte_t*)"\x0a\x00\x6a\x87",4);
|
receive_bytes();
|
||||||
//Receiving data: 0b 00 00 a4 04 00 06 e1 03 e1 03 e1 03
|
//Receiving data: 00 a4 04 00 06 e1 03 e1 03 e1 03
|
||||||
//= App Select by name "e103e103e103"
|
//= App Select by name "e103e103e103"
|
||||||
transmit_bytes((const byte_t*)"\x0b\x00\x6a\x87",4);
|
send_bytes((const byte_t*)"\x6a\x87",2);
|
||||||
//Receiving data: 0a 00 00 a4 04 00 07 d2 76 00 00 85 01 00
|
receive_bytes();
|
||||||
|
//Receiving data: 00 a4 04 00 06 e1 03 e1 03 e1 03
|
||||||
|
//= App Select by name "e103e103e103"
|
||||||
|
send_bytes((const byte_t*)"\x6a\x87",2);
|
||||||
|
receive_bytes();
|
||||||
|
//Receiving data: 00 a4 04 00 07 d2 76 00 00 85 01 00
|
||||||
//= App Select by name "D2760000850100"
|
//= App Select by name "D2760000850100"
|
||||||
transmit_bytes((const byte_t*)"\x0a\x00\x90\x00",4);
|
send_bytes((const byte_t*)"\x90\x00",2);
|
||||||
//Receiving data: 0b 00 00 a4 00 00 02 e1 03
|
receive_bytes();
|
||||||
|
//Receiving data: 00 a4 00 00 02 e1 03
|
||||||
//= Select CC
|
//= Select CC
|
||||||
transmit_bytes((const byte_t*)"\x0b\x00\x90\x00",4);
|
send_bytes((const byte_t*)"\x90\x00",2);
|
||||||
//Receiving data: 0a 00 00 b0 00 00 0f
|
receive_bytes();
|
||||||
|
//Receiving data: 00 b0 00 00 0f
|
||||||
//= ReadBinary CC
|
//= ReadBinary CC
|
||||||
//We send CC + OK
|
//We send CC + OK
|
||||||
transmit_bytes((const byte_t*)"\x0a\x00\x00\x0f\x10\x00\x3b\x00\x34\x04\x06\xe1\x04\x0e\xe0\x00\x00\x90\x00",19);
|
send_bytes((const byte_t*)"\x00\x0f\x10\x00\x3b\x00\x34\x04\x06\xe1\x04\x0e\xe0\x00\x00\x90\x00",17);
|
||||||
//Receiving data: 0b 00 00 a4 00 00 02 e1 04
|
receive_bytes();
|
||||||
|
//Receiving data: 00 a4 00 00 02 e1 04
|
||||||
//= Select NDEF
|
//= Select NDEF
|
||||||
transmit_bytes((const byte_t*)"\x0b\x00\x90\x00",4);
|
send_bytes((const byte_t*)"\x90\x00",2);
|
||||||
//Receiving data: 0a 00 00 b0 00 00 02
|
receive_bytes();
|
||||||
|
//Receiving data: 00 b0 00 00 02
|
||||||
//= Read first 2 NDEF bytes
|
//= Read first 2 NDEF bytes
|
||||||
//Sent NDEF Length=0x21
|
//Sent NDEF Length=0x21
|
||||||
transmit_bytes((const byte_t*)"\x0a\x00\x00\x21\x90\x00",6);
|
send_bytes((const byte_t*)"\x00\x21\x90\x00",4);
|
||||||
//Receiving data: 0b 00 00 b0 00 02 21
|
receive_bytes();
|
||||||
transmit_bytes((const byte_t*)"\x0b\x00\xd1\x02\x1c\x53\x70\x91\x01\x09\x54\x02\x65\x6e\x4c\x69\x62\x6e\x66\x63\x51\x01\x0b\x55\x03\x6c\x69\x62\x6e\x66\x63\x2e\x6f\x72\x67\x90\x00",37);
|
//Receiving data: 00 b0 00 02 21
|
||||||
//Receiving data: ca 00
|
//= Read remaining of NDEF file
|
||||||
//= S(DESELECT)
|
send_bytes((const byte_t*)"\xd1\x02\x1c\x53\x70\x91\x01\x09\x54\x02\x65\x6e\x4c\x69\x62\x6e\x66\x63\x51\x01\x0b\x55\x03\x6c\x69\x62\x6e\x66\x63\x2e\x6f\x72\x67\x90\x00",35);
|
||||||
// We don't have to reply ourselves because when using
|
|
||||||
// ISO/IEC14443-4 PICC mode, S(DESELECT) response is automatic
|
|
||||||
|
|
||||||
nfc_disconnect(pnd);
|
nfc_disconnect(pnd);
|
||||||
exit (EXIT_SUCCESS);
|
exit (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,8 @@ const byte_t pncmd_initiator_auto_poll[5] = { 0xD4, 0x60 };
|
||||||
const byte_t pncmd_target_get_data[2] = { 0xD4, 0x86 };
|
const byte_t pncmd_target_get_data[2] = { 0xD4, 0x86 };
|
||||||
const byte_t pncmd_target_set_data[264] = { 0xD4, 0x8E };
|
const byte_t pncmd_target_set_data[264] = { 0xD4, 0x8E };
|
||||||
const byte_t pncmd_target_init[39] = { 0xD4, 0x8C };
|
const byte_t pncmd_target_init[39] = { 0xD4, 0x8C };
|
||||||
|
//Example of default values:
|
||||||
|
//const byte_t pncmd_target_init[39] = { 0xD4, 0x8C, 0x00, 0x08, 0x00, 0x12, 0x34, 0x56, 0x40, 0x01, 0xFE, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xFF, 0xFF, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, 0x00 };
|
||||||
const byte_t pncmd_target_virtual_card[4] = { 0xD4, 0x14 };
|
const byte_t pncmd_target_virtual_card[4] = { 0xD4, 0x14 };
|
||||||
const byte_t pncmd_target_receive[2] = { 0xD4, 0x88 };
|
const byte_t pncmd_target_receive[2] = { 0xD4, 0x88 };
|
||||||
const byte_t pncmd_target_send[264] = { 0xD4, 0x90 };
|
const byte_t pncmd_target_send[264] = { 0xD4, 0x90 };
|
||||||
|
@ -947,7 +949,7 @@ pn53x_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, const nfc_ta
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
pn53x_set_parameters(pnd, SYMBOL_PARAM_fISO14443_4_PICC);
|
pn53x_set_parameters(pnd, SYMBOL_PARAM_fISO14443_4_PICC);
|
||||||
pn53x_configure(pnd, NDO_EASY_FRAMING, false);
|
pn53x_configure(pnd, NDO_EASY_FRAMING, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -1027,7 +1029,7 @@ pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm,
|
||||||
if (pbtNFCID3t) {
|
if (pbtNFCID3t) {
|
||||||
memcpy(abtCmd+27, pbtNFCID3t, 10);
|
memcpy(abtCmd+27, pbtNFCID3t, 10);
|
||||||
}
|
}
|
||||||
// TODO Handle General bytes and Tk (Historical bytes) lenght
|
// TODO Handle General bytes and Tk (Historical bytes) length
|
||||||
|
|
||||||
// Request the initialization as a target
|
// Request the initialization as a target
|
||||||
szRxLen = MAX_FRAME_LEN;
|
szRxLen = MAX_FRAME_LEN;
|
||||||
|
|
Loading…
Reference in a new issue