pn53x_check_communication() returns now 0 on success and libnfc error code on failure.

This commit is contained in:
Audrey Diacre 2012-01-04 16:19:24 +00:00
parent 240cdcddab
commit 7e1c776bc1
4 changed files with 14 additions and 10 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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;