From 6e7092b16033eb551e8f2194949033d66e29987f Mon Sep 17 00:00:00 2001 From: Audrey Diacre Date: Wed, 4 Jan 2012 15:30:42 +0000 Subject: [PATCH] nfc_initiator_transceive_bits() function does not now use pszRxBits as parameter because this function returns it. --- examples/nfc-anticol.c | 2 +- examples/nfc-relay.c | 6 +++--- include/nfc/nfc.h | 2 +- libnfc/chips/pn53x.c | 9 +++++---- libnfc/chips/pn53x.h | 3 +-- libnfc/nfc-internal.h | 2 +- libnfc/nfc.c | 5 ++--- utils/nfc-mfclassic.c | 5 ++--- utils/nfc-mfsetuid.c | 4 ++-- 9 files changed, 18 insertions(+), 20 deletions(-) diff --git a/examples/nfc-anticol.c b/examples/nfc-anticol.c index 20377e5..1080802 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) < 0) + if ((szRxBits = nfc_initiator_transceive_bits (pnd, pbtTx, szTxBits, NULL, abtRx, NULL)) < 0) return false; // Show received answer diff --git a/examples/nfc-relay.c b/examples/nfc-relay.c index 865ff60..4402fa2 100644 --- a/examples/nfc-relay.c +++ b/examples/nfc-relay.c @@ -55,7 +55,7 @@ static uint8_t abtReaderRxPar[MAX_FRAME_LEN]; static size_t szReaderRxBits; static uint8_t abtTagRx[MAX_FRAME_LEN]; static uint8_t abtTagRxPar[MAX_FRAME_LEN]; -static size_t szTagRxBits; +static int szTagRxBits; static nfc_device *pndReader; static nfc_device *pndTag; static bool quitting = false; @@ -196,8 +196,8 @@ main (int argc, char *argv[]) print_hex_par (abtReaderRx, szReaderRxBits, abtReaderRxPar); } // Forward the frame to the original tag - if (nfc_initiator_transceive_bits - (pndReader, abtReaderRx, szReaderRxBits, abtReaderRxPar, abtTagRx, &szTagRxBits, abtTagRxPar) > 0) { + if ((szTagRxBits = nfc_initiator_transceive_bits + (pndReader, abtReaderRx, szReaderRxBits, abtReaderRxPar, abtTagRx, abtTagRxPar)) > 0) { // Redirect the answer back to the reader if (nfc_target_send_bits (pndTag, abtTagRx, szTagRxBits, abtTagRxPar) < 0) { nfc_perror (pndTag, "nfc_target_send_bits"); diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index 006cfe1..f7c2640 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 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 int nfc_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar); NFC_EXPORT int 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 int 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 8be568b..aaeb8be 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -1110,11 +1110,12 @@ pn53x_initiator_select_dep_target(struct nfc_device *pnd, 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) + const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar) { int res = 0; size_t szFrameBits = 0; size_t szFrameBytes = 0; + size_t szRxBits = 0; uint8_t ui8rcc; uint8_t ui8Bits = 0; uint8_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN] = { InCommunicateThru }; @@ -1165,16 +1166,16 @@ pn53x_initiator_transceive_bits (struct nfc_device *pnd, const uint8_t *pbtTx, c // Unwrap the response frame if ((res = pn53x_unwrap_frame (abtRx + 1, szFrameBits, pbtRx, pbtRxPar)) < 0) return res; - *pszRxBits = res; + szRxBits = res; } else { // Save the received bits - *pszRxBits = szFrameBits; + szRxBits = szFrameBits; // Copy the received bytes memcpy (pbtRx, abtRx + 1, szRx - 1); } } // Everything went successful - return *pszRxBits; + return szRxBits; } int diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index 85b233c..d193612 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -298,8 +298,7 @@ int pn53x_initiator_select_dep_target (struct nfc_device *pnd, nfc_target *pnt, const int timeout); 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); + const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar); int pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, size_t *pszRx, int timeout); int pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, diff --git a/libnfc/nfc-internal.h b/libnfc/nfc-internal.h index adff35c..abebdd3 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); - 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); + int (*initiator_transceive_bits) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, uint8_t * pbtRxPar); int (*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); int (*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 371331d..1f620f4 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -527,7 +527,6 @@ nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const siz * nfc_initiator_transceive_bytes() function. * * @param[out] pbtRx response from the tag - * @param[out] pszRxBits \a pbtRx length in bits * @param[out] pbtRxPar parameter contains a byte array of the corresponding parity bits * * The NFC device (configured as \e initiator) will transmit low-level messages @@ -539,9 +538,9 @@ nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const siz */ 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) + uint8_t *pbtRx, uint8_t *pbtRxPar) { - HAL (initiator_transceive_bits, pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pszRxBits, pbtRxPar); + HAL (initiator_transceive_bits, pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pbtRxPar); } /** diff --git a/utils/nfc-mfclassic.c b/utils/nfc-mfclassic.c index c585d47..c784a7c 100644 --- a/utils/nfc-mfclassic.c +++ b/utils/nfc-mfclassic.c @@ -82,7 +82,7 @@ static size_t num_keys = sizeof (keys) / 6; #define MAX_FRAME_LEN 264 static uint8_t abtRx[MAX_FRAME_LEN]; -static size_t szRxBits; +static int szRxBits; static size_t szRx = sizeof(abtRx); uint8_t abtHalt[4] = { 0x50, 0x00, 0x00, 0x00 }; @@ -98,8 +98,7 @@ 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 - int res = 0; - if ((res = nfc_initiator_transceive_bits (pnd, pbtTx, szTxBits, NULL, abtRx, &szRxBits, NULL)) < 0) + if ((szRxBits = nfc_initiator_transceive_bits (pnd, pbtTx, szTxBits, NULL, abtRx, NULL)) < 0) return false; // Show received answer diff --git a/utils/nfc-mfsetuid.c b/utils/nfc-mfsetuid.c index 521dada..5ef33e4 100644 --- a/utils/nfc-mfsetuid.c +++ b/utils/nfc-mfsetuid.c @@ -57,7 +57,7 @@ #define MAX_FRAME_LEN 264 static uint8_t abtRx[MAX_FRAME_LEN]; -static size_t szRxBits; +static int szRxBits; static size_t szRx = sizeof(abtRx); static uint8_t abtRawUid[12]; static uint8_t abtAtqa[2]; @@ -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) < 0) + if ((szRxBits = nfc_initiator_transceive_bits (pnd, pbtTx, szTxBits, NULL, abtRx, NULL)) < 0) return false; // Show received answer