- Add timeout capablities to nfc_initiator_transceive_bytes(), nfc_target_send_bytes() and nfc_target_receive_bytes();

- Bump version to 1.5.1.
This commit is contained in:
Romain Tartiere
2011-09-22 13:03:47 +00:00
parent e94513fdb7
commit 481fb4943f
32 changed files with 210 additions and 162 deletions
+8 -2
View File
@@ -252,8 +252,11 @@ acr122_disconnect (nfc_device_t * pnd)
}
bool
acr122_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData)
acr122_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout)
{
// FIXME: timeout is not handled
(void) timeout;
// Make sure the command does not overflow the send buffer
if (szData > ACR122_COMMAND_LEN) {
pnd->iLastError = EINVALARG;
@@ -320,8 +323,11 @@ acr122_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData)
}
int
acr122_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData)
acr122_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout)
{
// FIXME: timeout is not handled
(void) timeout;
int len;
byte_t abtRxCmd[5] = { 0xFF, 0xC0, 0x00, 0x00 };
+2 -2
View File
@@ -30,8 +30,8 @@ bool acr122_probe (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t
// Functions used by developer to handle connection to this device
nfc_device_t *acr122_connect (const nfc_device_desc_t * pndd);
bool acr122_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData);
int acr122_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData);
bool acr122_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout);
int acr122_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout);
void acr122_disconnect (nfc_device_t * pnd);
extern const struct nfc_driver_t acr122_driver;
+16 -16
View File
@@ -236,7 +236,7 @@ arygon_disconnect (nfc_device_t * pnd)
#define ARYGON_TX_BUFFER_LEN (PN53x_NORMAL_FRAME__DATA_MAX_LEN + PN53x_NORMAL_FRAME__OVERHEAD + 1)
#define ARYGON_RX_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
bool
arygon_tama_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData)
arygon_tama_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout)
{
// Before sending anything, we need to discard from any junk bytes
uart_flush_input (DRIVER_DATA(pnd)->port);
@@ -256,7 +256,7 @@ arygon_tama_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szDat
return false;
}
int res = uart_send (DRIVER_DATA (pnd)->port, abtFrame, szFrame + 1);
int res = uart_send (DRIVER_DATA (pnd)->port, abtFrame, szFrame + 1, timeout);
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)");
pnd->iLastError = res;
@@ -264,7 +264,7 @@ arygon_tama_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szDat
}
byte_t abtRxBuf[6];
res = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, sizeof (abtRxBuf), 0);
res = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, sizeof (abtRxBuf), 0, timeout);
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to read ACK");
pnd->iLastError = res;
@@ -277,7 +277,7 @@ arygon_tama_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szDat
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Bad frame format." );
// We have already read 6 bytes and arygon_error_unknown_mode is 10 bytes long
// so we have to read 4 remaining bytes to be synchronized at the next receiving pass.
uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 4, 0);
uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 4, 0, timeout);
return false;
} else {
return false;
@@ -291,14 +291,14 @@ arygon_abort (nfc_device_t *pnd)
// Send a valid TAMA packet to wakup the PN53x (we will not have an answer, according to Arygon manual)
byte_t dummy[] = { 0x32, 0x00, 0x00, 0xff, 0x09, 0xf7, 0xd4, 0x00, 0x00, 0x6c, 0x69, 0x62, 0x6e, 0x66, 0x63, 0xbe, 0x00 };
uart_send (DRIVER_DATA (pnd)->port, dummy, sizeof (dummy));
uart_send (DRIVER_DATA (pnd)->port, dummy, sizeof (dummy), NULL);
// Using Arygon device we can't send ACK frame to abort the running command
return (pn53x_check_communication (pnd)) ? 0 : -1;
}
int
arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen)
arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout)
{
byte_t abtRxBuf[5];
size_t len;
@@ -320,7 +320,7 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe
break;
}
pnd->iLastError = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 5, abort_p);
pnd->iLastError = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 5, abort_p, timeout);
if (abort_p && (EOPABORT == pnd->iLastError)) {
arygon_abort (pnd);
@@ -344,7 +344,7 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe
if ((0x01 == abtRxBuf[3]) && (0xff == abtRxBuf[4])) {
// Error frame
uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 3, 0);
uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 3, 0, timeout);
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Application level error detected");
pnd->iLastError = EFRAISERRFRAME;
return -1;
@@ -372,7 +372,7 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe
}
// TFI + PD0 (CC+1)
pnd->iLastError = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 2, 0);
pnd->iLastError = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 2, 0, timeout);
if (pnd->iLastError != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
return -1;
@@ -391,14 +391,14 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe
}
if (len) {
pnd->iLastError = uart_receive (DRIVER_DATA (pnd)->port, pbtData, len, 0);
pnd->iLastError = uart_receive (DRIVER_DATA (pnd)->port, pbtData, len, 0, timeout);
if (pnd->iLastError != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
return -1;
}
}
pnd->iLastError = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 2, 0);
pnd->iLastError = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 2, 0, timeout);
if (pnd->iLastError != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
return -1;
@@ -428,17 +428,17 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe
void
arygon_firmware (nfc_device_t * pnd, char * str)
{
const byte_t arygon_firmware_version_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'v' };
const byte_t arygon_firmware_version_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'v' };
byte_t abtRx[16];
size_t szRx = sizeof(abtRx);
int res = uart_send (DRIVER_DATA (pnd)->port, arygon_firmware_version_cmd, sizeof (arygon_firmware_version_cmd));
int res = uart_send (DRIVER_DATA (pnd)->port, arygon_firmware_version_cmd, sizeof (arygon_firmware_version_cmd), NULL);
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Unable to send ARYGON firmware command.");
return;
}
res = uart_receive (DRIVER_DATA (pnd)->port, abtRx, szRx, 0);
res = uart_receive (DRIVER_DATA (pnd)->port, abtRx, szRx, 0, NULL);
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Unable to retrieve ARYGON firmware version.");
return;
@@ -461,11 +461,11 @@ arygon_reset_tama (nfc_device_t * pnd)
size_t szRx = sizeof(abtRx);
int res;
uart_send (DRIVER_DATA (pnd)->port, arygon_reset_tama_cmd, sizeof (arygon_reset_tama_cmd));
uart_send (DRIVER_DATA (pnd)->port, arygon_reset_tama_cmd, sizeof (arygon_reset_tama_cmd), NULL);
// Two reply are possible from ARYGON device: arygon_error_none (ie. in case the byte is well-sent)
// or arygon_error_unknown_mode (ie. in case of the first byte was bad-transmitted)
res = uart_receive (DRIVER_DATA (pnd)->port, abtRx, szRx, 0);
res = uart_receive (DRIVER_DATA (pnd)->port, abtRx, szRx, 0, NULL);
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "No reply to 'reset TAMA' command.");
return false;
+4 -2
View File
@@ -26,6 +26,8 @@
#ifndef __NFC_DRIVER_ARYGON_H__
# define __NFC_DRIVER_ARYGON_H__
# include <sys/time.h>
# include <nfc/nfc-types.h>
bool arygon_probe (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound);
@@ -33,8 +35,8 @@ bool arygon_probe (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t
nfc_device_t *arygon_connect (const nfc_device_desc_t * pndd);
void arygon_disconnect (nfc_device_t * pnd);
bool arygon_tama_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData);
int arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData);
bool arygon_tama_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout);
int arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDat, struct timeval *timeouta);
extern const struct nfc_driver_t arygon_driver;
+13 -13
View File
@@ -215,14 +215,14 @@ pn532_uart_wakeup (nfc_device_t * pnd)
{
/* High Speed Unit (HSU) wake up consist to send 0x55 and wait a "long" delay for PN532 being wakeup. */
const byte_t pn532_wakeup_preamble[] = { 0x55, 0x55, 0x00, 0x00, 0x00 };
int res = uart_send (DRIVER_DATA(pnd)->port, pn532_wakeup_preamble, sizeof (pn532_wakeup_preamble));
int res = uart_send (DRIVER_DATA(pnd)->port, pn532_wakeup_preamble, sizeof (pn532_wakeup_preamble), NULL);
CHIP_DATA(pnd)->power_mode = NORMAL; // PN532 should now be awake
return res;
}
#define PN532_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
bool
pn532_uart_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData)
pn532_uart_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout)
{
// Before sending anything, we need to discard from any junk bytes
uart_flush_input (DRIVER_DATA(pnd)->port);
@@ -258,7 +258,7 @@ pn532_uart_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData
return false;
}
int res = uart_send (DRIVER_DATA(pnd)->port, abtFrame, szFrame);
int res = uart_send (DRIVER_DATA(pnd)->port, abtFrame, szFrame, timeout);
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)");
pnd->iLastError = res;
@@ -266,7 +266,7 @@ pn532_uart_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData
}
byte_t abtRxBuf[6];
res = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 6, 0);
res = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 6, 0, timeout);
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to read ACK");
pnd->iLastError = res;
@@ -282,7 +282,7 @@ pn532_uart_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData
}
int
pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen)
pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout)
{
byte_t abtRxBuf[5];
size_t len;
@@ -304,7 +304,7 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
break;
}
pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 5, abort_p);
pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 5, abort_p, timeout);
if (abort_p && (EOPABORT == pnd->iLastError)) {
pn532_uart_ack (pnd);
@@ -325,13 +325,13 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
if ((0x01 == abtRxBuf[3]) && (0xff == abtRxBuf[4])) {
// Error frame
uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 3, 0);
uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 3, 0, timeout);
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Application level error detected");
pnd->iLastError = EFRAISERRFRAME;
return -1;
} else if ((0xff == abtRxBuf[3]) && (0xff == abtRxBuf[4])) {
// Extended frame
pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 3, 0);
pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 3, 0, timeout);
if (pnd->iLastError) return -1;
// (abtRxBuf[0] << 8) + abtRxBuf[1] (LEN) include TFI + (CC+1)
@@ -362,7 +362,7 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
}
// TFI + PD0 (CC+1)
pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 2, 0);
pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 2, 0, timeout);
if (pnd->iLastError != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
return -1;
@@ -381,14 +381,14 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
}
if (len) {
pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, pbtData, len, 0);
pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, pbtData, len, 0, timeout);
if (pnd->iLastError != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
return -1;
}
}
pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 2, 0);
pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 2, 0, timeout);
if (pnd->iLastError != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
return -1;
@@ -423,10 +423,10 @@ pn532_uart_ack (nfc_device_t * pnd)
return -1;
}
}
return (0 == uart_send (DRIVER_DATA(pnd)->port, pn53x_ack_frame, sizeof (pn53x_ack_frame))) ? 0 : -1;
return (0 == uart_send (DRIVER_DATA(pnd)->port, pn53x_ack_frame, sizeof (pn53x_ack_frame), NULL)) ? 0 : -1;
}
bool
bool
pn532_uart_abort_command (nfc_device_t * pnd)
{
if (pnd) {
+4 -2
View File
@@ -25,14 +25,16 @@
#ifndef __NFC_DRIVER_PN532_UART_H__
# define __NFC_DRIVER_PN532_UART_H__
# include <sys/time.h>
# include <nfc/nfc-types.h>
bool pn532_uart_probe (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound);
nfc_device_t *pn532_uart_connect (const nfc_device_desc_t * pndd);
void pn532_uart_disconnect (nfc_device_t * pnd);
bool pn532_uart_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData);
int pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData);
bool pn532_uart_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout);
int pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout);
extern const struct nfc_driver_t pn532_uart_driver;
+35 -30
View File
@@ -89,40 +89,34 @@ bool pn53x_usb_get_usb_device_name (struct usb_device *dev, usb_dev_handle *udev
bool pn53x_usb_init (nfc_device_t *pnd);
int
pn53x_usb_bulk_read (struct pn53x_usb_data *data, byte_t abtRx[], const size_t szRx)
pn53x_usb_bulk_read (struct pn53x_usb_data *data, byte_t abtRx[], const size_t szRx, struct timeval *timeout)
{
int res = usb_bulk_read (data->pudh, data->uiEndPointIn, (char *) abtRx, szRx, USB_INFINITE_TIMEOUT);
if (res > 0) {
LOG_HEX ("RX", abtRx, res);
} else if (res < 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to read from USB (%s", _usb_strerror (res));
}
return res;
}
int
int timeout_ms = USB_INFINITE_TIMEOUT;
if (timeout)
timeout_ms = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
pn53x_usb_bulk_read_ex (struct pn53x_usb_data *data, byte_t abtRx[], const size_t szRx, int timeout)
{
int res = usb_bulk_read (data->pudh, data->uiEndPointIn, (char *) abtRx, szRx, timeout);
int res = usb_bulk_read (data->pudh, data->uiEndPointIn, (char *) abtRx, szRx, timeout_ms);
if (res > 0) {
LOG_HEX ("RX", abtRx, res);
} else if (res < 0) {
if (-res != USB_TIMEDOUT) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to read from USB (%s)", _usb_strerror (res));
}
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to read from USB (%s)", _usb_strerror (res));
}
return res;
}
int
pn53x_usb_bulk_write (struct pn53x_usb_data *data, byte_t abtTx[], const size_t szTx)
pn53x_usb_bulk_write (struct pn53x_usb_data *data, byte_t abtTx[], const size_t szTx, struct timeval *timeout)
{
LOG_HEX ("TX", abtTx, szTx);
int res = usb_bulk_write (data->pudh, data->uiEndPointOut, (char *) abtTx, szTx, USB_INFINITE_TIMEOUT);
int timeout_ms = USB_INFINITE_TIMEOUT;
if (timeout)
timeout_ms = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
int res = usb_bulk_write (data->pudh, data->uiEndPointOut, (char *) abtTx, szTx, timeout_ms);
if (res > 0) {
// HACK This little hack is a well know problem of USB, see http://www.libusb.org/ticket/6 for more details
if ((res % data->uiMaxPacketSize) == 0) {
usb_bulk_write (data->pudh, data->uiEndPointOut, "\0", 0, USB_INFINITE_TIMEOUT);
usb_bulk_write (data->pudh, data->uiEndPointOut, "\0", 0, timeout_ms);
}
} else {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to write to USB (%s)", _usb_strerror (res));
@@ -154,7 +148,7 @@ pn53x_usb_get_device_model (uint16_t vendor_id, uint16_t product_id)
(product_id == pn53x_usb_supported_devices[n].product_id))
return pn53x_usb_supported_devices[n].model;
}
return UNKNOWN;
}
@@ -414,14 +408,14 @@ pn53x_usb_disconnect (nfc_device_t * pnd)
#define PN53X_USB_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
bool
pn53x_usb_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData)
pn53x_usb_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout)
{
byte_t abtFrame[PN53X_USB_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
size_t szFrame = 0;
pn53x_build_frame (abtFrame, &szFrame, pbtData, szData);
int res = pn53x_usb_bulk_write (DRIVER_DATA (pnd), abtFrame, szFrame);
int res = pn53x_usb_bulk_write (DRIVER_DATA (pnd), abtFrame, szFrame, timeout);
if (res < 0) {
pnd->iLastError = ECOMIO;
@@ -429,7 +423,7 @@ pn53x_usb_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData)
}
byte_t abtRxBuf[PN53X_USB_BUFFER_LEN];
res = pn53x_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf));
res = pn53x_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf), timeout);
if (res < 0) {
pnd->iLastError = ECOMIO;
// try to interrupt current device state
@@ -446,7 +440,7 @@ pn53x_usb_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData)
// response packet. With this hack, the nextly executed function (ie.
// pn53x_usb_receive()) will be able to retreive the correct response
// packet.
int res = pn53x_usb_bulk_write (DRIVER_DATA (pnd), (byte_t *)pn53x_nack_frame, sizeof(pn53x_nack_frame));
int res = pn53x_usb_bulk_write (DRIVER_DATA (pnd), (byte_t *)pn53x_nack_frame, sizeof(pn53x_nack_frame), timeout);
if (res < 0) {
pnd->iLastError = ECOMIO;
// try to interrupt current device state
@@ -459,7 +453,7 @@ pn53x_usb_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData)
}
int
pn53x_usb_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen)
pn53x_usb_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout)
{
size_t len;
off_t offset = 0;
@@ -467,8 +461,11 @@ pn53x_usb_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen)
switch (CHIP_DATA (pnd)->ui8LastCommand) {
case InDataExchange:
case InJumpForDEP:
case TgGetData:
if (!timeout)
delayed_reply = true;
break;
case InJumpForDEP:
case TgInitAsTarget:
delayed_reply = true;
break;
@@ -479,8 +476,16 @@ pn53x_usb_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen)
byte_t abtRxBuf[PN53X_USB_BUFFER_LEN];
int res;
/*
* If no timeout is specified but the command is blocking, force a 250ms
* timeout to allow breaking the loop if the user wants to stop it.
*/
struct timeval fixed_timeout = {
.tv_sec = 0,
.tv_usec = 250000,
};
read:
res = pn53x_usb_bulk_read_ex (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf), delayed_reply ? 250 : USB_INFINITE_TIMEOUT);
res = pn53x_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf), (delayed_reply && !timeout) ? &fixed_timeout : timeout);
if (delayed_reply && (res == -USB_TIMEDOUT)) {
if (DRIVER_DATA (pnd)->abort_flag) {
@@ -590,7 +595,7 @@ read:
int
pn53x_usb_ack (nfc_device_t * pnd)
{
return pn53x_usb_bulk_write (DRIVER_DATA (pnd), (byte_t *) pn53x_ack_frame, sizeof (pn53x_ack_frame));
return pn53x_usb_bulk_write (DRIVER_DATA (pnd), (byte_t *) pn53x_ack_frame, sizeof (pn53x_ack_frame), NULL);
}
bool
@@ -599,13 +604,13 @@ pn53x_usb_init (nfc_device_t *pnd)
// Sometimes PN53x USB doesn't reply ACK one the first frame, so we need to send a dummy one...
//pn53x_check_communication (pnd); // Sony RC-S360 doesn't support this command for now so let's use a get_firmware_version instead:
const byte_t abtCmd[] = { GetFirmwareVersion };
pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL);
pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL);
// ...and we don't care about error
pnd->iLastError = 0;
if (SONY_RCS360 == DRIVER_DATA (pnd)->model) {
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "SONY RC-S360 initialization.");
const byte_t abtCmd2[] = { 0x18, 0x01 };
pn53x_transceive (pnd, abtCmd2, sizeof (abtCmd2), NULL, NULL);
pn53x_transceive (pnd, abtCmd2, sizeof (abtCmd2), NULL, NULL, NULL);
pn53x_usb_ack (pnd);
}
+4 -2
View File
@@ -25,12 +25,14 @@
#ifndef __NFC_DRIVER_PN53X_USB_H__
# define __NFC_DRIVER_PN53X_USB_H__
# include <sys/time.h>
# include <nfc/nfc-types.h>
bool pn53x_usb_probe (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound);
nfc_device_t *pn53x_usb_connect (const nfc_device_desc_t * pndd);
bool pn53x_usb_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData);
int pn53x_usb_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData);
bool pn53x_usb_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout);
int pn53x_usb_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout);
void pn53x_usb_disconnect (nfc_device_t * pnd);
extern const struct nfc_driver_t pn53x_usb_driver;