From 6fc4a5b70a340751611c826950f744ae5ca76354 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 27 Apr 2011 14:42:27 +0000 Subject: [PATCH] Use a new current target pointer to choose correctly the sending/receiving method (ie. TgSetData/TgGetData or TgResponseToInitiator/TgGetInitiatorCommand). --- libnfc/chips/pn53x.c | 40 ++++++++++++++++++++++++++++++++++------ libnfc/chips/pn53x.h | 1 + 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 758520d..aa910c2 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -68,6 +68,9 @@ pn53x_init(nfc_device_t * pnd) return false; } + // Set current target to NULL + CHIP_DATA (pnd)->current_target = NULL; + // CRC handling is enabled by default pnd->bCrc = true; // Parity handling is enabled by default @@ -1244,6 +1247,9 @@ bool pn53x_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar, uint16_t * cycles) { + // TODO Do something with these bytes... + (void) pbtTxPar; + (void) pbtRxPar; unsigned int i; uint8_t sz; @@ -1559,6 +1565,12 @@ pn53x_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_ if (pnt->nm.nmt == NMT_DEP) { pnt->nti.ndi.ndm = ndm; // Update DEP mode } + // Keep the current nfc_target for further commands + if (CHIP_DATA (pnd)->current_target) { + free (CHIP_DATA (pnd)->current_target); + } + CHIP_DATA (pnd)->current_target = malloc (sizeof(nfc_target_t)); + memcpy (CHIP_DATA (pnd)->current_target, pnt, sizeof(nfc_target_t)); } } @@ -1682,10 +1694,17 @@ pn53x_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx) { byte_t abtCmd[1]; - // FIXME In DEP mode we MUST use TgGetData but we don't known the current mode. - // DEP mode && EasyFramming || EasyFramming && ISO14443-4 && PN532 - if (pnd->bEasyFraming && (CHIP_DATA(pnd)->type == PN532)) { - abtCmd[0] = TgGetData; + if (pnd->bEasyFraming) { + if ((CHIP_DATA (pnd)->current_target->nm.nmt == NMT_DEP) || // If DEP mode + ((CHIP_DATA(pnd)->type == PN532) && (pnd->bAutoIso14443_4) && + (CHIP_DATA (pnd)->current_target->nm.nmt == NMT_ISO14443A) && (CHIP_DATA (pnd)->current_target->nti.nai.btSak & SAK_ISO14443_4_COMPLIANT)) // If ISO14443-4 PICC emulation + ) { + abtCmd[0] = TgGetData; + } else { + // TODO Support EasyFraming for other cases by software + pnd->iLastError = DENOTSUP; + return false; + } } else { abtCmd[0] = TgGetInitiatorCommand; } @@ -1755,8 +1774,17 @@ pn53x_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t if (!pnd->bPar) return false; - if (pnd->bEasyFraming && (CHIP_DATA(pnd)->type == PN532)) { - abtCmd[0] = TgSetData; + if (pnd->bEasyFraming) { + if ((CHIP_DATA (pnd)->current_target->nm.nmt == NMT_DEP) || // If DEP mode + ((CHIP_DATA(pnd)->type == PN532) && (pnd->bAutoIso14443_4) && + (CHIP_DATA (pnd)->current_target->nm.nmt == NMT_ISO14443A) && (CHIP_DATA (pnd)->current_target->nti.nai.btSak & SAK_ISO14443_4_COMPLIANT)) // If ISO14443-4 PICC emulation + ) { + abtCmd[0] = TgSetData; + } else { + // TODO Support EasyFraming for other cases by software + pnd->iLastError = DENOTSUP; + return false; + } } else { abtCmd[0] = TgResponseToInitiator; } diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index f64b4a1..9918096 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -150,6 +150,7 @@ struct pn53x_io { struct pn53x_data { pn53x_type type; pn53x_power_mode power_mode; + nfc_target_t* current_target; const struct pn53x_io * io; /** Register cache for REG_CIU_BIT_FRAMING, SYMBOL_TX_LAST_BITS: The last TX bits setting, we need to reset this if it does not apply anymore */ uint8_t ui8TxBits;