From 8fe13ece6282cbde4e3d5badaf5ef5948a3c0805 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 19 Aug 2013 15:47:44 +0200 Subject: [PATCH] pn53x_initiator_transceive_bytes_timed(): use proper CRC_B if TypeB --- libnfc/chips/pn53x.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index fadcdfb..4dfe8f8 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -1605,6 +1605,13 @@ pn53x_initiator_transceive_bytes_timed(struct nfc_device *pnd, const uint8_t *pb return pnd->last_error; } + uint8_t txmode = 0; + if (pnd->bCrc) { // check if we're in TypeA or TypeB mode to compute right CRC later + if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_TxMode, &txmode)) < 0) { + return res; + } + } + __pn53x_init_timer(pnd, *cycles); // Once timer is started, we cannot use Tama commands anymore. @@ -1689,7 +1696,12 @@ pn53x_initiator_transceive_bytes_timed(struct nfc_device *pnd, const uint8_t *pb if (!pbtTxRaw) return NFC_ESOFT; memcpy(pbtTxRaw, pbtTx, szTx); - iso14443a_crc_append(pbtTxRaw, szTx); + if ((txmode & SYMBOL_TX_FRAMING) == 0x00) + iso14443a_crc_append(pbtTxRaw, szTx); + else if ((txmode & SYMBOL_TX_FRAMING) == 0x03) + iso14443b_crc_append(pbtTxRaw, szTx); + else + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unsupported framing type %02X, cannot adjust CRC cycles", txmode & SYMBOL_TX_FRAMING); *cycles = __pn53x_get_timer(pnd, pbtTxRaw[szTx + 1]); free(pbtTxRaw); } else {