From 7e1c776bc1fe9a82bffbe343459d340795643c92 Mon Sep 17 00:00:00 2001 From: Audrey Diacre Date: Wed, 4 Jan 2012 16:19:24 +0000 Subject: [PATCH] pn53x_check_communication() returns now 0 on success and libnfc error code on failure. --- libnfc/chips/pn53x.c | 12 ++++++++---- libnfc/chips/pn53x.h | 2 +- libnfc/drivers/arygon.c | 2 +- libnfc/drivers/pn532_uart.c | 8 ++++---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index c65022b..cc19323 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -870,18 +870,22 @@ pn53x_idle (struct nfc_device *pnd) return true; } -bool +int pn53x_check_communication (struct nfc_device *pnd) { const uint8_t abtCmd[] = { Diagnose, 0x00, 'l', 'i', 'b', 'n', 'f', 'c' }; const uint8_t abtExpectedRx[] = { 0x00, 'l', 'i', 'b', 'n', 'f', 'c' }; uint8_t abtRx[sizeof(abtExpectedRx)]; size_t szRx = sizeof (abtRx); + int res = 0; - if (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, 1000) < 0) - return false; + if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, 1000)) < 0) + return res; - return ((sizeof(abtExpectedRx) == szRx) && (0 == memcmp (abtRx, abtExpectedRx, sizeof(abtExpectedRx)))); + if (((sizeof(abtExpectedRx) == szRx) && (0 == memcmp (abtRx, abtExpectedRx, sizeof(abtExpectedRx)))) == 0) + return NFC_ECHIP; + + return NFC_SUCCESS; } int diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index d53e732..ceafa75 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -279,7 +279,7 @@ int pn53x_get_firmware_version (struct nfc_device *pnd, char abtFirmwareText[ int pn53x_set_property_int (struct nfc_device *pnd, const nfc_property property, const int value); int pn53x_set_property_bool (struct nfc_device *pnd, const nfc_property property, const bool bEnable); -bool pn53x_check_communication (struct nfc_device *pnd); +int pn53x_check_communication (struct nfc_device *pnd); bool pn53x_idle (struct nfc_device *pnd); // NFC device as Initiator functions diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index 602f144..ec20056 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -362,7 +362,7 @@ arygon_abort (nfc_device *pnd) uart_send (DRIVER_DATA (pnd)->port, dummy, sizeof (dummy), 0); // Using Arygon device we can't send ACK frame to abort the running command - return (pn53x_check_communication (pnd)) ? 0 : -1; + return (pn53x_check_communication (pnd) == 0) ? 0 : -1; } int diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 5906eba..ce3147d 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -114,14 +114,14 @@ pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t * #endif // Check communication using "Diagnose" command, with "Communication test" (0x00) - bool res = pn53x_check_communication (pnd); - if(!res) { + int res = pn53x_check_communication (pnd); + if(res < 0) { nfc_perror (pnd, "pn53x_check_communication"); } pn53x_data_free (pnd); nfc_device_free (pnd); uart_close (sp); - if(!res) { + if(res < 0) { continue; } @@ -251,7 +251,7 @@ pn532_uart_connect (const nfc_connstring connstring) #endif // Check communication using "Diagnose" command, with "Communication test" (0x00) - if (!pn53x_check_communication (pnd)) { + if (pn53x_check_communication (pnd) < 0) { nfc_perror (pnd, "pn53x_check_communication"); pn532_uart_disconnect (pnd); return NULL;