nfc_target_init() now update nfc_target_t baud rate

This commit is contained in:
Romuald Conty 2010-10-14 16:27:50 +00:00
parent 7294e4fbaf
commit 7c76e1bf32
11 changed files with 45 additions and 37 deletions

View file

@ -65,9 +65,9 @@ main (int argc, const char *argv[])
return EXIT_FAILURE;
}
const nfc_target_t nt = {
nfc_target_t nt = {
.nm.nmt = NMT_DEP,
.nm.nbr = NBR_UNDEFINED, // Not used by nfc_target_init
.nm.nbr = NBR_UNDEFINED, // Will be updated by nfc_target_init
.nti.ndi.abtNFCID3 = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff, 0x00, 0x00 },
.nti.ndi.szGB = 4,
.nti.ndi.abtGB = { 0x12, 0x34, 0x56, 0x78 },
@ -89,7 +89,7 @@ main (int argc, const char *argv[])
print_nfc_target (nt);
printf ("Waiting for initiator request...\n");
if(!nfc_target_init (pnd, NTM_DEP_ONLY, nt, abtRx, &szRx)) {
if(!nfc_target_init (pnd, NTM_DEP_ONLY, &nt, abtRx, &szRx)) {
nfc_perror(pnd, "nfc_target_init");
return EXIT_FAILURE;
}

View file

@ -113,7 +113,7 @@ main (int argc, char *argv[])
nfc_target_t nt = {
.nm.nmt = NMT_ISO14443A,
.nm.nbr = NBR_UNDEFINED,
.nm.nbr = NBR_UNDEFINED, // Will be updated by nfc_target_init()
.nti.nai.abtAtqa = { 0x00, 0x04 },
.nti.nai.abtUid = { 0x08, 0x00, 0xb0, 0x0b },
.nti.nai.btSak = 0x20,
@ -121,7 +121,7 @@ main (int argc, char *argv[])
.nti.nai.szAtsLen = 0,
};
if (!nfc_target_init (pnd, NTM_ISO14443_4_PICC_ONLY, nt, abtRx, &szRx)) {
if (!nfc_target_init (pnd, NTM_ISO14443_4_PICC_ONLY, &nt, abtRx, &szRx)) {
nfc_perror (pnd, "nfc_target_init");
ERR("Could not come out of auto-emulation, no command was received");
return EXIT_FAILURE;

View file

@ -61,7 +61,7 @@ intr_hdlr (void)
}
bool
target_io( const nfc_target_t nt, const byte_t * pbtInput, const size_t szInput, byte_t * pbtOutput, size_t *pszOutput )
target_io( nfc_target_t * pnt, const byte_t * pbtInput, const size_t szInput, byte_t * pbtOutput, size_t *pszOutput )
{
bool loop = true;
*pszOutput = 0;
@ -84,10 +84,10 @@ target_io( const nfc_target_t nt, const byte_t * pbtInput, const size_t szInput,
break;
case 0xe0: // RATS
// Send ATS
*pszOutput = nt.nti.nai.szAtsLen + 1;
pbtOutput[0] = nt.nti.nai.szAtsLen + 1; // ISO14443-4 says that ATS contains ATS_Lenght as first byte
if(nt.nti.nai.szAtsLen) {
memcpy(pbtOutput+1, nt.nti.nai.abtAts, nt.nti.nai.szAtsLen);
*pszOutput = pnt->nti.nai.szAtsLen + 1;
pbtOutput[0] = pnt->nti.nai.szAtsLen + 1; // ISO14443-4 says that ATS contains ATS_Lenght as first byte
if(pnt->nti.nai.szAtsLen) {
memcpy(pbtOutput+1, pnt->nti.nai.abtAts, pnt->nti.nai.szAtsLen);
}
break;
case 0xc2: // S-block DESELECT
@ -112,19 +112,19 @@ target_io( const nfc_target_t nt, const byte_t * pbtInput, const size_t szInput,
}
bool
nfc_target_emulate_tag(nfc_device_t* pnd, const nfc_target_t nt)
nfc_target_emulate_tag(nfc_device_t* pnd, nfc_target_t * pnt)
{
size_t szTx;
byte_t abtTx[MAX_FRAME_LEN];
bool loop = true;
if (!nfc_target_init (pnd, NTM_PASSIVE_ONLY, nt, abtRx, &szRx)) {
if (!nfc_target_init (pnd, NTM_PASSIVE_ONLY, pnt, abtRx, &szRx)) {
nfc_perror (pnd, "nfc_target_init");
return false;
}
while ( loop ) {
loop = target_io( nt, abtRx, szRx, abtTx, &szTx );
loop = target_io( pnt, abtRx, szRx, abtTx, &szTx );
if (szTx) {
if (!nfc_target_send_bytes(pnd, abtTx, szTx)) {
nfc_perror (pnd, "nfc_target_send_bytes");
@ -209,7 +209,7 @@ main (int argc, char *argv[])
print_nfc_iso14443a_info( nt.nti.nai );
printf ("NFC device (configured as target) is now emulating the tag, please touch it with a second NFC device (initiator)\n");
if (!nfc_target_emulate_tag (pnd, nt)) {
if (!nfc_target_emulate_tag (pnd, &nt)) {
nfc_perror (pnd, "nfc_target_emulate_tag");
return EXIT_FAILURE;
}

View file

@ -140,7 +140,7 @@ main (int argc, char *argv[])
.nti.nai.szUidLen = 4,
.nti.nai.szAtsLen = 0,
};
if (!nfc_target_init (pnd, NTM_PASSIVE_ONLY, nt, abtRecv, &szRecvBits)) {
if (!nfc_target_init (pnd, NTM_PASSIVE_ONLY, &nt, abtRecv, &szRecvBits)) {
ERR ("Could not come out of auto-emulation, no command was received");
exit(EXIT_FAILURE);
}

View file

@ -343,7 +343,7 @@ main (int argc, char *argv[])
printf ("Connected to the NFC emulator device: %s\n", pndTarget->acName);
if (!nfc_target_init (pndTarget, NTM_ISO14443_4_PICC_ONLY, ntEmulatedTarget, abtCapdu, &szCapduLen)) {
if (!nfc_target_init (pndTarget, NTM_ISO14443_4_PICC_ONLY, &ntEmulatedTarget, abtCapdu, &szCapduLen)) {
ERR ("%s", "Initialization of NFC emulator failed");
if (!target_only_mode) {
nfc_disconnect (pndInitiator);

View file

@ -136,7 +136,7 @@ main (int argc, char *argv[])
.nti.nai.szAtsLen = 0,
};
if (!nfc_target_init (pndTag, NTM_PASSIVE_ONLY, nt, abtReaderRx, &szReaderRxBits)) {
if (!nfc_target_init (pndTag, NTM_PASSIVE_ONLY, &nt, abtReaderRx, &szReaderRxBits)) {
ERR ("%s", "Initialization of NFC emulator failed");
nfc_disconnect (pndTag);
return EXIT_FAILURE;

View file

@ -212,7 +212,7 @@ main (int argc, const char *argv[])
};
printf ("Now both, NFC device (configured as target) and SAM are readables from an external NFC initiator.\n");
printf ("Please note that NFC device (configured as target) stay in target mode until it receive RATS, ATR_REQ or proprietary command.\n");
if (!nfc_target_init (pnd, NTM_NORMAL, nt, abtRx, &szRx)) {
if (!nfc_target_init (pnd, NTM_NORMAL, &nt, abtRx, &szRx)) {
nfc_perror(pnd, "nfc_target_init");
return EXIT_FAILURE;
}