From 7f2b300dde67dea5c82ff3849b3fae785bd37b41 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 4 Apr 2011 22:23:38 +0000 Subject: [PATCH] support crc auto-handling in ...transceive_bytes_timed --- libnfc/chips/pn53x.c | 22 +++++++++++++--------- libnfc/nfc.c | 3 +-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index ce28d2b..ef867a4 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -1195,15 +1195,14 @@ pn53x_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx, unsigned int i; uint8_t sz; - // We can not just send bytes without parity while the PN53X expects we handled them + // Sorry, no arbitrary parity bits support for now if (!pnd->bPar) return false; // Sorry, no easy framing support - // TODO: to be changed once we'll provide easy framing support from libnfc itself... if (pnd->bEasyFraming) return false; // Sorry, no CRC support - // TODO: to be changed once we'll provide easy CRC support from libnfc itself... + // TODO but it probably doesn't make sense for (szTxBits % 8 != 0) ... if (pnd->bCrc) return false; @@ -1293,10 +1292,6 @@ pn53x_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx // TODO: to be changed once we'll provide easy framing support from libnfc itself... if (pnd->bEasyFraming) return false; - // Sorry, no CRC support - // TODO: to be changed once we'll provide easy CRC support from libnfc itself... - if (pnd->bCrc) - return false; __pn53x_init_timer(pnd); @@ -1321,8 +1316,17 @@ pn53x_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx } // Recv corrected timer value - *cycles = __pn53x_get_timer (pnd, pbtTx[szTx -1]); - + if (pnd->bCrc) { + // We've to compute CRC ourselves to know last byte actually sent + uint8_t * pbtTxRaw; + pbtTxRaw = (uint8_t *) malloc(szTx+2); + memcpy (pbtTxRaw, pbtTx, szTx); + iso14443a_crc_append (pbtTxRaw, szTx); + *cycles = __pn53x_get_timer (pnd, pbtTxRaw[szTx +1]); + free(pbtTxRaw); + } else { + *cycles = __pn53x_get_timer (pnd, pbtTx[szTx -1]); + } return true; } diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 95d31b8..b55e241 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -541,11 +541,10 @@ nfc_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const s * * This function is similar to nfc_initiator_transceive_bytes() with the following differences: * - A precise cycles counter will indicate the number of cycles between emission & reception of frames. - * - It only supports mode with \a NDO_EASY_FRAMING option disabled and CRC must be handled manually. + * - It only supports mode with \a NDO_EASY_FRAMING option disabled. * - Overall communication with the host is heavier and slower. * * @warning The configuration option \a NDO_EASY_FRAMING must be set to \c false. - * @warning The configuration option \a NDO_HANDLE_CRC must be set to \c false. * @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value). */ bool