From ffe50562dd7f77586e621753058c7c3b68251be9 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 14 Oct 2010 18:33:17 +0000 Subject: [PATCH] Make use of the now available Tk info --- examples/nfc-relay-picc.c | 14 +++++++++++--- include/nfc/nfc-types.h | 2 +- include/nfc/nfc.h | 2 +- libnfc/chips/pn53x.c | 2 +- libnfc/iso14443-subr.c | 6 +++--- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/examples/nfc-relay-picc.c b/examples/nfc-relay-picc.c index e3cafe8..c6c9963 100644 --- a/examples/nfc-relay-picc.c +++ b/examples/nfc-relay-picc.c @@ -320,13 +320,21 @@ main (int argc, char *argv[]) // | +-------- DR=2,4 DS=2,4 => supports 106, 212 & 424bps in both directions // +----------- TA,TB,TC, FSCI=5 => FSC=64 // It seems hazardous to tell we support NAD if the tag doesn't support NAD but I don't know how to disable it - // PC/SC pseudo-ATR = 3B 80 80 01 01 + // PC/SC pseudo-ATR = 3B 80 80 01 01 if there is no historical bytes + + // Creates ATS and copy max 48 bytes of Tk: + byte_t * pbtTk; + size_t szTk; + pbtTk = iso14443a_locate_historical_bytes (ntEmulatedTarget.nti.nai.abtAts, ntEmulatedTarget.nti.nai.szAts, &szTk); + szTk = (szTk > 48) ? 48 : szTk; + byte_t pbtTkt[48]; + memcpy(pbtTkt, pbtTk, szTk); ntEmulatedTarget.nti.nai.abtAts[0] = 0x75; ntEmulatedTarget.nti.nai.abtAts[1] = 0x33; ntEmulatedTarget.nti.nai.abtAts[2] = 0x92; ntEmulatedTarget.nti.nai.abtAts[3] = 0x03; - ntEmulatedTarget.nti.nai.szAtsLen = 4; - //FIXME we could actually emulate also the historical bytes of the tag once libnfc API supports it... + ntEmulatedTarget.nti.nai.szAtsLen = 4 + szTk; + memcpy(&(ntEmulatedTarget.nti.nai.abtAts[4]), pbtTkt, szTk); printf("We will emulate:\n"); print_nfc_iso14443a_info (ntEmulatedTarget.nti.nai); diff --git a/include/nfc/nfc-types.h b/include/nfc/nfc-types.h index 06cf9cf..c63c31a 100644 --- a/include/nfc/nfc-types.h +++ b/include/nfc/nfc-types.h @@ -206,7 +206,7 @@ typedef struct { size_t szUidLen; byte_t abtUid[10]; size_t szAtsLen; - byte_t abtAts[36]; + byte_t abtAts[254]; // Maximal theoretical ATS is FSD-2, FSD=256 for FSDI=8 in RATS } nfc_iso14443a_info_t; /** diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index fdfdf81..181c8be 100644 --- a/include/nfc/nfc.h +++ b/include/nfc/nfc.h @@ -107,7 +107,7 @@ extern "C" { /* Misc. functions */ NFC_EXPORT void iso14443a_crc (byte_t * pbtData, size_t szLen, byte_t * pbtCrc); NFC_EXPORT void append_iso14443a_crc (byte_t * pbtData, size_t szLen); - NFC_EXPORT byte_t * iso14443a_extract_historical_bytes (byte_t * pbtAts, size_t szAts, size_t * pszHB); + NFC_EXPORT byte_t * iso14443a_locate_historical_bytes (byte_t * pbtAts, size_t szAts, size_t * pszTk); NFC_EXPORT const char *nfc_version (void); /* Common device-level errors */ diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index a6d6217..fedd299 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -1184,7 +1184,7 @@ pn53x_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, nfc_target_t pbtMifareParams = abtMifareParams; // Historical Bytes - pbtHBt = iso14443a_extract_historical_bytes (pnt->nti.nai.abtAts, pnt->nti.nai.szAtsLen, &szHBt); + pbtHBt = iso14443a_locate_historical_bytes (pnt->nti.nai.abtAts, pnt->nti.nai.szAtsLen, &szHBt); } break; diff --git a/libnfc/iso14443-subr.c b/libnfc/iso14443-subr.c index 18b4051..032c57a 100644 --- a/libnfc/iso14443-subr.c +++ b/libnfc/iso14443-subr.c @@ -54,7 +54,7 @@ append_iso14443a_crc (byte_t * pbtData, size_t szLen) } byte_t * -iso14443a_extract_historical_bytes(byte_t * pbtAts, size_t szAts, size_t * pszHB) +iso14443a_locate_historical_bytes(byte_t * pbtAts, size_t szAts, size_t * pszTk) { if (szAts) { size_t offset = 1; @@ -68,10 +68,10 @@ iso14443a_extract_historical_bytes(byte_t * pbtAts, size_t szAts, size_t * pszHB offset++; } if (szAts > offset) { - *pszHB = (szAts-offset); + *pszTk = (szAts-offset); return (pbtAts+offset); } } - *pszHB = 0; + *pszTk = 0; return NULL; }