From 97dd0b63d76aaec99322884191ec2d2a007f0bdd Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Fri, 4 Mar 2011 20:17:28 +0000 Subject: [PATCH] Implement abort for pn532_uart driver. --- libnfc/chips/pn53x.h | 2 +- libnfc/drivers/pn532_uart.c | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index af88dc2..7cd8f0d 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -195,7 +195,7 @@ typedef enum { PTM_ISO14443_4_PICC_ONLY = 0x04 } pn53x_target_mode_t; -bool pn53x_init(nfc_device_t * pnd); +bool pn53x_init(nfc_device_t * pnd); bool pn53x_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t *pszRx); bool pn53x_read_register (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t * ui8Value); bool pn53x_write_register (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t ui8SymbolMask, uint8_t ui8Value); diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 9b53d0b..f6479e1 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -48,7 +48,7 @@ // TODO Move this one level up for libnfc-1.6 static const byte_t ack_frame[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00 }; -void pn532_uart_ack (nfc_device_t * pnd); +int pn532_uart_ack (nfc_device_t * pnd); // void pn532_uart_wakeup (const nfc_device_spec_t nds); struct pn532_uart_data { @@ -223,8 +223,24 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen { byte_t abtRxBuf[5]; size_t len; + int abort_fd = 0; + + switch (pnd->iLastCommand) { + case InAutoPoll: + case TgInitAsTarget: + case TgGetData: + abort_fd = pnd->iAbortFds[1]; + break; + default: + break; + } + + int res = uart_receive (((struct pn532_uart_data*)(pnd->driver_data))->port, abtRxBuf, 5, abort_fd); + + if (abort_fd && (DEABORT == res)) { + return pn532_uart_ack (pnd); + } - int res = uart_receive (((struct pn532_uart_data*)(pnd->driver_data))->port, abtRxBuf, 5, 0); if (res != 0) { ERR ("%s", "Unable to receive data. (RX)"); pnd->iLastError = res; @@ -324,10 +340,11 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen return len; } -void +int pn532_uart_ack (nfc_device_t * pnd) { - uart_send (((struct pn532_uart_data*)(pnd->driver_data))->port, ack_frame, sizeof (ack_frame)); + ((struct pn53x_data*)(pnd->chip_data))->state = NORMAL; + return (0 == uart_send (((struct pn532_uart_data*)(pnd->driver_data))->port, ack_frame, sizeof (ack_frame))) ? 0 : -1; } const struct nfc_driver_t pn532_uart_driver = {