From 2cca743e07550aa30605006ac095600d329f8059 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Wed, 9 Mar 2011 14:10:40 +0000 Subject: [PATCH] Return an error when a command is aborted; Fix aborting with UART devices. --- examples/nfc-emulate-forum-tag4.c | 6 +++--- libnfc/drivers/arygon.c | 28 ++++++++++++++-------------- libnfc/drivers/pn532_uart.c | 25 +++++++++++-------------- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/examples/nfc-emulate-forum-tag4.c b/examples/nfc-emulate-forum-tag4.c index b64f57b..0531f39 100644 --- a/examples/nfc-emulate-forum-tag4.c +++ b/examples/nfc-emulate-forum-tag4.c @@ -124,7 +124,7 @@ main (void) if (pnd == NULL) { ERR("Unable to connect to NFC device"); - return EXIT_FAILURE; + exit (EXIT_FAILURE); } signal (SIGINT, stop_emulation); @@ -152,11 +152,11 @@ main (void) print_nfc_iso14443a_info (nt.nti.nai, true); if (!nfc_target_init (pnd, &nt, abtRx, &szRx)) { if (pnd->iLastError == DEABORT) { - errx (EXIT_SUCCESS, "Operation canceld by keystroke."); + errx (EXIT_SUCCESS, "Operation canceled by keystroke."); } nfc_perror (pnd, "nfc_target_init"); ERR("Could not come out of auto-emulation, no command was received"); - return EXIT_FAILURE; + exit (EXIT_FAILURE); } if (!quiet_output) { diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index 70de471..c03d159 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -263,15 +263,18 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe break; } - int res = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 5, abort_fd); + pnd->iLastError = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 5, abort_fd); - if (abort_fd && (DEABORT == res)) { - return arygon_abort (pnd); + if (abort_fd && (DEABORT == pnd->iLastError)) { + arygon_abort (pnd); + + /* iLastError got reset by arygon_abort() */ + pnd->iLastError = DEABORT; + return -1; } - if (res != 0) { + if (pnd->iLastError != 0) { ERR ("%s", "Unable to receive data. (RX)"); - pnd->iLastError = res; return -1; } @@ -312,10 +315,9 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe } // TFI + PD0 (CC+1) - res = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 2, 0); - if (res != 0) { + pnd->iLastError = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 2, 0); + if (pnd->iLastError != 0) { ERR ("%s", "Unable to receive data. (RX)"); - pnd->iLastError = res; return -1; } @@ -332,18 +334,16 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe } if (len) { - res = uart_receive (DRIVER_DATA (pnd)->port, pbtData, len, 0); - if (res != 0) { + pnd->iLastError = uart_receive (DRIVER_DATA (pnd)->port, pbtData, len, 0); + if (pnd->iLastError != 0) { ERR ("%s", "Unable to receive data. (RX)"); - pnd->iLastError = res; return -1; } } - res = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 2, 0); - if (res != 0) { + pnd->iLastError = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 2, 0); + if (pnd->iLastError != 0) { ERR ("%s", "Unable to receive data. (RX)"); - pnd->iLastError = res; return -1; } diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 736c057..8e3f5f0 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -243,15 +243,15 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen break; } - int res = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 5, abort_fd); + pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 5, abort_fd); - if (abort_fd && (DEABORT == res)) { - return pn532_uart_ack (pnd); + if (abort_fd && (DEABORT == pnd->iLastError)) { + pn532_uart_ack (pnd); + return -1; } - if (res != 0) { + if (pnd->iLastError != 0) { ERR ("%s", "Unable to receive data. (RX)"); - pnd->iLastError = res; return -1; } @@ -292,10 +292,9 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen } // TFI + PD0 (CC+1) - res = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 2, 0); - if (res != 0) { + pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 2, 0); + if (pnd->iLastError != 0) { ERR ("%s", "Unable to receive data. (RX)"); - pnd->iLastError = res; return -1; } @@ -312,18 +311,16 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen } if (len) { - res = uart_receive (DRIVER_DATA(pnd)->port, pbtData, len, 0); - if (res != 0) { + pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, pbtData, len, 0); + if (pnd->iLastError != 0) { ERR ("%s", "Unable to receive data. (RX)"); - pnd->iLastError = res; return -1; } } - res = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 2, 0); - if (res != 0) { + pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 2, 0); + if (pnd->iLastError != 0) { ERR ("%s", "Unable to receive data. (RX)"); - pnd->iLastError = res; return -1; }