From 642f9a38f776acbad27ec7a355313e5fd705a164 Mon Sep 17 00:00:00 2001 From: Audrey Diacre Date: Thu, 5 Jan 2012 16:33:55 +0000 Subject: [PATCH] nfc_target_receive_bytes() function does not now use pszRx as parameter because this function returns it. --- examples/nfc-dep-target.c | 2 +- examples/nfc-emulate-tag.c | 2 +- include/nfc/nfc.h | 2 +- libnfc/chips/pn53x.c | 8 ++++---- libnfc/chips/pn53x.h | 2 +- libnfc/nfc-emulation.c | 2 +- libnfc/nfc-internal.h | 2 +- libnfc/nfc.c | 5 ++--- test/test_dep_active.c | 6 +++--- test/test_dep_passive.c | 18 +++++++++--------- utils/nfc-relay-picc.c | 2 +- 11 files changed, 25 insertions(+), 26 deletions(-) diff --git a/examples/nfc-dep-target.c b/examples/nfc-dep-target.c index ad2e275..77a912f 100644 --- a/examples/nfc-dep-target.c +++ b/examples/nfc-dep-target.c @@ -125,7 +125,7 @@ main (int argc, const char *argv[]) } printf("Initiator request received. Waiting for data...\n"); - if (nfc_target_receive_bytes (pnd, abtRx, &szRx, 0) < 0) { + if (((int) (szRx = (size_t) nfc_target_receive_bytes (pnd, abtRx, 0))) < 0) { nfc_perror(pnd, "nfc_target_receive_bytes"); goto error; } diff --git a/examples/nfc-emulate-tag.c b/examples/nfc-emulate-tag.c index 9936a7d..3604ab7 100644 --- a/examples/nfc-emulate-tag.c +++ b/examples/nfc-emulate-tag.c @@ -158,7 +158,7 @@ nfc_target_emulate_tag(nfc_device *pnd, nfc_target *pnt) nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, false); init_mfc_auth = false; } - if (nfc_target_receive_bytes(pnd, abtRx, &szRx, 0) < 0) { + if ((int) ((szRx = (size_t) nfc_target_receive_bytes(pnd, abtRx, 0))) < 0) { nfc_perror (pnd, "nfc_target_receive_bytes"); return false; } diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index 51d2b7b..6d4f475 100644 --- a/include/nfc/nfc.h +++ b/include/nfc/nfc.h @@ -85,7 +85,7 @@ extern "C" { /* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */ NFC_EXPORT int nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t *pszRx, int timeout); NFC_EXPORT int nfc_target_send_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout); - NFC_EXPORT int nfc_target_receive_bytes (nfc_device *pnd, uint8_t *pbtRx, size_t *pszRx, int timeout); + NFC_EXPORT int nfc_target_receive_bytes (nfc_device *pnd, uint8_t *pbtRx, int timeout); NFC_EXPORT int nfc_target_send_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar); NFC_EXPORT int nfc_target_receive_bits (nfc_device *pnd, uint8_t *pbtRx, uint8_t *pbtRxPar); diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index dfbc6be..c6be8b8 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -1851,7 +1851,7 @@ pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, uint8_t *pbtR } int -pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszRx, int timeout) +pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, int timeout) { uint8_t abtCmd[1]; @@ -1890,13 +1890,13 @@ pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszR return pnd->last_error; // Save the received bytes count - *pszRx = szRx - 1; + szRx -= 1; // Copy the received bytes - memcpy (pbtRx, abtRx + 1, *pszRx); + memcpy (pbtRx, abtRx + 1, szRx); // Everyting seems ok, return received bytes count - return *pszRx; + return szRx; } int diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index 7ea7731..66ccdc0 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -310,7 +310,7 @@ int pn53x_initiator_deselect_target (struct nfc_device *pnd); // NFC device as Target functions int pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t *pszRx, int timeout); int pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, uint8_t *pbtRxPar); -int pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszRx, int timeout); +int pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, int timeout); int pn53x_target_send_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar); int pn53x_target_send_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout); diff --git a/libnfc/nfc-emulation.c b/libnfc/nfc-emulation.c index 435363c..21db471 100644 --- a/libnfc/nfc-emulation.c +++ b/libnfc/nfc-emulation.c @@ -47,7 +47,7 @@ nfc_emulate_target (nfc_device *pnd, struct nfc_emulator *emulator) } } if (res >= 0) { - if (nfc_target_receive_bytes(pnd, abtRx, &szRx, 0) < 0) { + if ((int) ((szRx = (size_t) nfc_target_receive_bytes(pnd, abtRx, 0))) < 0) { return -1; } } diff --git a/libnfc/nfc-internal.h b/libnfc/nfc-internal.h index 91646ce..1de9216 100644 --- a/libnfc/nfc-internal.h +++ b/libnfc/nfc-internal.h @@ -144,7 +144,7 @@ struct nfc_driver_t { int (*target_init) (struct nfc_device *pnd, nfc_target * pnt, uint8_t * pbtRx, size_t * pszRx, int timeout); int (*target_send_bytes) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, int timeout); - int (*target_receive_bytes) (struct nfc_device *pnd, uint8_t * pbtRx, size_t * pszRx, int timeout); + int (*target_receive_bytes) (struct nfc_device *pnd, uint8_t * pbtRx, int timeout); int (*target_send_bits) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar); int (*target_receive_bits) (struct nfc_device *pnd, uint8_t * pbtRx, uint8_t * pbtRxPar); diff --git a/libnfc/nfc.c b/libnfc/nfc.c index d482715..b810803 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -719,7 +719,6 @@ nfc_target_send_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, * * @param pnd \a nfc_device struct pointer that represent currently used device * @param[out] pbtRx pointer to Rx buffer - * @param[out] pszRx received byte count * @param timeout in milliseconds * * This function retrieves bytes frames (e.g. ADPU) sent by the \e initiator to the NFC device (configured as \e target). @@ -728,9 +727,9 @@ nfc_target_send_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, * If timeout is a null pointer, the function blocks indefinitely (until an error is raised or function is completed). */ int -nfc_target_receive_bytes (nfc_device *pnd, uint8_t *pbtRx, size_t *pszRx, int timeout) +nfc_target_receive_bytes (nfc_device *pnd, uint8_t *pbtRx, int timeout) { - HAL (target_receive_bytes, pnd, pbtRx, pszRx, timeout); + HAL (target_receive_bytes, pnd, pbtRx, timeout); } /** diff --git a/test/test_dep_active.c b/test/test_dep_active.c index 85d992b..71235aa 100644 --- a/test/test_dep_active.c +++ b/test/test_dep_active.c @@ -85,11 +85,11 @@ target_thread (void *arg) uint8_t abtRx[1024]; size_t szRx = sizeof (abtRx); int res = nfc_target_init (device, &nt, abtRx, &szRx, 0); - cut_assert_equal_int (0, res, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device))); + cut_assert_operator_int (res, >, 0, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device))); if (res < 0) { thread_res = -1; return (void*) thread_res; } - res = nfc_target_receive_bytes (device, abtRx, &szRx, 500); - cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); + szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500); + cut_assert_operator_int (szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); const uint8_t abtAttRx[] = "Hello DEP target!"; cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); diff --git a/test/test_dep_passive.c b/test/test_dep_passive.c index 9db5151..a6af765 100644 --- a/test/test_dep_passive.c +++ b/test/test_dep_passive.c @@ -83,12 +83,12 @@ target_thread (void *arg) uint8_t abtRx[1024]; size_t szRx = sizeof (abtRx); int res = nfc_target_init (device, &nt, abtRx, &szRx, 0); - cut_assert_equal_int (0, res, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device))); + cut_assert_operator_int (res, >, 0, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device))); if (res < 0) { thread_res = -1; return (void*) thread_res; } // First pass - res = nfc_target_receive_bytes (device, abtRx, &szRx, 500); - cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); + szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500); + cut_assert_operator_int ((int) szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); const uint8_t abtAttRx[] = "Hello DEP target!"; cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); @@ -100,8 +100,8 @@ target_thread (void *arg) if (res <= 0) { thread_res = -1; return (void*) thread_res; } // Second pass - res = nfc_target_receive_bytes (device, abtRx, &szRx, 500); - cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); + szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500); + cut_assert_operator_int ((int) szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); if (res <= 0) { thread_res = -1; return (void*) thread_res; } @@ -111,8 +111,8 @@ target_thread (void *arg) if (res <= 0) { thread_res = -1; return (void*) thread_res; } // Third pass - res = nfc_target_receive_bytes (device, abtRx, &szRx, 500); - cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); + szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500); + cut_assert_operator_int ((int) szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); if (res <= 0) { thread_res = -1; return (void*) thread_res; } @@ -122,8 +122,8 @@ target_thread (void *arg) if (res <= 0) { thread_res = -1; return (void*) thread_res; } // Fourth pass - res = nfc_target_receive_bytes (device, abtRx, &szRx, 500); - cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); + szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500); + cut_assert_operator_int ((int)szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); if (res <= 0) { thread_res = -1; return (void*) thread_res; } diff --git a/utils/nfc-relay-picc.c b/utils/nfc-relay-picc.c index 3c5caf5..d80e7ed 100644 --- a/utils/nfc-relay-picc.c +++ b/utils/nfc-relay-picc.c @@ -370,7 +370,7 @@ main (int argc, char *argv[]) bool ret; if (!initiator_only_mode) { // Receive external reader command through target - if (nfc_target_receive_bytes(pndTarget,abtCapdu,&szCapduLen, 0) < 0) { + if ((int) ((szCapduLen = (size_t) nfc_target_receive_bytes(pndTarget, abtCapdu, 0))) < 0) { nfc_perror (pndTarget, "nfc_target_receive_bytes"); if (!target_only_mode) { nfc_disconnect (pndInitiator);