diff --git a/examples/nfc-anticol.c b/examples/nfc-anticol.c index 6bcc4ed..20377e5 100644 --- a/examples/nfc-anticol.c +++ b/examples/nfc-anticol.c @@ -83,7 +83,7 @@ transmit_bits (const uint8_t *pbtTx, const size_t szTxBits) print_hex_bits (pbtTx, szTxBits); } // Transmit the bit frame command, we don't use the arbitrary parity feature - if (!nfc_initiator_transceive_bits (pnd, pbtTx, szTxBits, NULL, abtRx, &szRxBits, NULL)) + if (nfc_initiator_transceive_bits (pnd, pbtTx, szTxBits, NULL, abtRx, &szRxBits, NULL) < 0) return false; // Show received answer diff --git a/examples/nfc-relay.c b/examples/nfc-relay.c index 7b3f803..7f4597a 100644 --- a/examples/nfc-relay.c +++ b/examples/nfc-relay.c @@ -197,7 +197,7 @@ main (int argc, char *argv[]) } // Forward the frame to the original tag if (nfc_initiator_transceive_bits - (pndReader, abtReaderRx, szReaderRxBits, abtReaderRxPar, abtTagRx, &szTagRxBits, abtTagRxPar)) { + (pndReader, abtReaderRx, szReaderRxBits, abtReaderRxPar, abtTagRx, &szTagRxBits, abtTagRxPar) > 0) { // Redirect the answer back to the reader if (!nfc_target_send_bits (pndTag, abtTagRx, szTagRxBits, abtTagRxPar)) { nfc_perror (pndTag, "nfc_target_send_bits"); diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index d02f451..8d6309d 100644 --- a/include/nfc/nfc.h +++ b/include/nfc/nfc.h @@ -78,7 +78,7 @@ extern "C" { NFC_EXPORT int nfc_initiator_select_dep_target (nfc_device *pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info *pndiInitiator, nfc_target *pnt, const int timeout); NFC_EXPORT int nfc_initiator_deselect_target (nfc_device *pnd); NFC_EXPORT int nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, size_t *pszRx, int timeout); - NFC_EXPORT bool nfc_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar); + NFC_EXPORT int nfc_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar); NFC_EXPORT bool nfc_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, size_t *pszRx, uint32_t *cycles); NFC_EXPORT bool nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar, uint32_t *cycles); diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 1ef18d5..c129985 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -1107,10 +1107,11 @@ pn53x_initiator_select_dep_target(struct nfc_device *pnd, } } -bool +int pn53x_initiator_transceive_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar) { + int res = 0; size_t szFrameBits = 0; size_t szFrameBytes = 0; uint8_t ui8rcc; @@ -1136,19 +1137,19 @@ pn53x_initiator_transceive_bits (struct nfc_device *pnd, const uint8_t *pbtTx, c memcpy (abtCmd + 1, pbtTx, szFrameBytes); // Set the amount of transmission bits in the PN53X chip register - if (pn53x_set_tx_bits (pnd, ui8Bits) < 0) - return false; + if ((res = pn53x_set_tx_bits (pnd, ui8Bits)) < 0) + return res; // Send the frame to the PN53X chip and get the answer // We have to give the amount of bytes + (the command byte 0x42) uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRx = sizeof(abtRx); - if (pn53x_transceive (pnd, abtCmd, szFrameBytes + 1, abtRx, &szRx, -1) < 0) - return false; + if ((res = pn53x_transceive (pnd, abtCmd, szFrameBytes + 1, abtRx, &szRx, -1)) < 0) + return res; // Get the last bit-count that is stored in the received byte - if (pn53x_read_register (pnd, PN53X_REG_CIU_Control, &ui8rcc) < 0) - return false; + if ((res = pn53x_read_register (pnd, PN53X_REG_CIU_Control, &ui8rcc)) < 0) + return res; ui8Bits = ui8rcc & SYMBOL_RX_LAST_BITS; // Recover the real frame length in bits @@ -1168,7 +1169,7 @@ pn53x_initiator_transceive_bits (struct nfc_device *pnd, const uint8_t *pbtTx, c } } // Everything went successful - return true; + return *pszRxBits; } int diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index aa33453..10bca76 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -299,7 +299,7 @@ int pn53x_initiator_select_dep_target (struct nfc_device *pnd, const nfc_dep_info *pndiInitiator, nfc_target *pnt, const int timeout); -bool pn53x_initiator_transceive_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, +int pn53x_initiator_transceive_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar); int pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, diff --git a/libnfc/nfc-internal.h b/libnfc/nfc-internal.h index 359140b..1a20465 100644 --- a/libnfc/nfc-internal.h +++ b/libnfc/nfc-internal.h @@ -138,7 +138,7 @@ struct nfc_driver_t { int (*initiator_select_dep_target) (struct nfc_device *pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info * pndiInitiator, nfc_target * pnt, const int timeout); int (*initiator_deselect_target) (struct nfc_device *pnd); int (*initiator_transceive_bytes) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, int timeout); - bool (*initiator_transceive_bits) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar); + int (*initiator_transceive_bits) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar); bool (*initiator_transceive_bytes_timed) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, uint32_t * cycles); bool (*initiator_transceive_bits_timed) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar, uint32_t * cycles); diff --git a/libnfc/nfc.c b/libnfc/nfc.c index c6d40d4..d006986 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -504,7 +504,7 @@ nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const siz /** * @brief Transceive raw bit-frames to a target - * @return Returns \c true if action was successfully performed; otherwise returns \c false. + * @return Returns received bits count on success, otherwise returns libnfc's error code * * @param pbtTx contains a byte array of the frame that needs to be transmitted. * @param szTxBits contains the length in bits. @@ -537,7 +537,7 @@ nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const siz * require to violate the ISO14443-A standard by sending incorrect parity and * CRC bytes. Using this feature you are able to simulate these frames. */ -bool +int nfc_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar) { diff --git a/utils/nfc-mfclassic.c b/utils/nfc-mfclassic.c index c2ae78c..c585d47 100644 --- a/utils/nfc-mfclassic.c +++ b/utils/nfc-mfclassic.c @@ -98,7 +98,8 @@ transmit_bits (const uint8_t *pbtTx, const size_t szTxBits) printf ("Sent bits: "); print_hex_bits (pbtTx, szTxBits); // Transmit the bit frame command, we don't use the arbitrary parity feature - if (!nfc_initiator_transceive_bits (pnd, pbtTx, szTxBits, NULL, abtRx, &szRxBits, NULL)) + int res = 0; + if ((res = nfc_initiator_transceive_bits (pnd, pbtTx, szTxBits, NULL, abtRx, &szRxBits, NULL)) < 0) return false; // Show received answer diff --git a/utils/nfc-mfsetuid.c b/utils/nfc-mfsetuid.c index ea0af5c..521dada 100644 --- a/utils/nfc-mfsetuid.c +++ b/utils/nfc-mfsetuid.c @@ -96,7 +96,7 @@ transmit_bits (const uint8_t *pbtTx, const size_t szTxBits) print_hex_bits (pbtTx, szTxBits); } // Transmit the bit frame command, we don't use the arbitrary parity feature - if (!nfc_initiator_transceive_bits (pnd, pbtTx, szTxBits, NULL, abtRx, &szRxBits, NULL)) + if (nfc_initiator_transceive_bits (pnd, pbtTx, szTxBits, NULL, abtRx, &szRxBits, NULL) < 0) return false; // Show received answer