From b333a4b1cfd0cf31548ddc6cf5f9b6d2ddf7234c Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Tue, 12 Oct 2010 09:44:39 +0000 Subject: [PATCH] Add FeliCa to emulation capabilities --- examples/nfc-emulate-tag.c | 11 ++++++++++- libnfc/chips/pn53x.c | 24 ++++++++++++++++++++++-- libnfc/chips/pn53x.h | 2 +- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/examples/nfc-emulate-tag.c b/examples/nfc-emulate-tag.c index e5523fb..47896b9 100644 --- a/examples/nfc-emulate-tag.c +++ b/examples/nfc-emulate-tag.c @@ -152,7 +152,7 @@ main (int argc, char *argv[]) } printf ("Connected to NFC device: %s\n", pnd->acName); - + // Example of a Mifare Classic Mini // Note that crypto1 is not implemented in this example nfc_target_t nt = { @@ -163,6 +163,15 @@ main (int argc, char *argv[]) .nti.nai.szUidLen = 4, .nti.nai.szAtsLen = 0, }; +/* + // Example of a FeliCa + nfc_target_t nt = { + .ntt = NTT_FELICA_212, + .nti.nfi.abtId = { 0x01, 0xFE, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF }, + .nti.nfi.abtPad = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF }, + .nti.nfi.abtSysCode = { 0xFF, 0xFF }, + }; +*/ /* // Example of a ISO14443-4 (DESfire) nfc_target_t nt = { diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 327a9e1..1973b55 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -1062,7 +1062,9 @@ pn53x_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, const nfc_ta return false; byte_t abtMifareParams[6]; + byte_t abtFeliCaParams[18]; byte_t * pbtMifareParams = NULL; + byte_t * pbtFeliCaParams = NULL; const byte_t * pbtNFCID3t = NULL; const byte_t * pbtGB = NULL; @@ -1086,6 +1088,18 @@ pn53x_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, const nfc_ta pbtMifareParams = abtMifareParams; } break; + + case NTT_FELICA_212: + case NTT_FELICA_424: + // Set NFCID2t + memcpy(abtFeliCaParams, nt.nti.nfi.abtId, 8); + // Set PAD + memcpy(abtFeliCaParams+8, nt.nti.nfi.abtPad, 8); + // Set SystemCode + memcpy(abtFeliCaParams+16, nt.nti.nfi.abtSysCode, 2); + pbtFeliCaParams = abtFeliCaParams; + break; + case NTT_DEP_PASSIVE_106: case NTT_DEP_PASSIVE_212: case NTT_DEP_PASSIVE_424: @@ -1095,7 +1109,7 @@ pn53x_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, const nfc_ta break; } - if(!pn53x_TgInitAsTarget(pnd, ntm, pbtMifareParams, NULL, pbtNFCID3t, pbtGB, szGB, pbtRx, pszRxLen)) { + if(!pn53x_TgInitAsTarget(pnd, ntm, pbtMifareParams, pbtFeliCaParams, pbtNFCID3t, pbtGB, szGB, pbtRx, pszRxLen, NULL)) { return false; } @@ -1113,7 +1127,7 @@ pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm, const byte_t * pbtMifareParams, const byte_t * pbtFeliCaParams, const byte_t * pbtNFCID3t, const byte_t * pbtGB, const size_t szGB, - byte_t * pbtRx, size_t * pszRxLen) + byte_t * pbtRx, size_t * pszRxLen, byte_t * pbtModeByte) { byte_t abtRx[MAX_FRAME_LEN]; size_t szRxLen; @@ -1128,12 +1142,15 @@ pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm, // Store the target mode in the initialization params abtCmd[2] = ntm; + // MIFARE part if (pbtMifareParams) { memcpy (abtCmd+3, pbtMifareParams, 6); } + // FeliCa part if (pbtFeliCaParams) { memcpy (abtCmd+9, pbtFeliCaParams, 18); } + // DEP part if (pbtNFCID3t) { memcpy(abtCmd+27, pbtNFCID3t, 10); } @@ -1156,6 +1173,9 @@ pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm, // Note: the first byte is skip: // its the "mode" byte which contains baudrate, DEP and Framing type (Mifare, active or FeliCa) datas. + if(pbtModeByte) { + *pbtModeByte = pbtRx[0]; + } // Save the received byte count *pszRxLen = szRxLen - 1; diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index f4362e6..602f533 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -152,7 +152,7 @@ bool pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm, const byte_t * pbtMifareParams, const byte_t * pbtFeliCaParams, const byte_t * pbtNFCID3t, const byte_t * pbtGB, const size_t szGB, - byte_t * pbtRx, size_t * pszRxLen); + byte_t * pbtRx, size_t * pszRxLen, byte_t * pbtModeByte); #endif // __NFC_CHIPS_PN53X_H__