libnfc/drivers: pn532_uart_ack() and arygon_reset_tama() functions return now libnfc error code on failure.

This commit is contained in:
Audrey Diacre 2012-01-05 13:56:12 +00:00
parent c30e9eed36
commit 5d4f22c548
2 changed files with 19 additions and 17 deletions

View file

@ -88,7 +88,7 @@ static const uint8_t arygon_error_none[] = "FF000000\x0d\x0a";
static const uint8_t arygon_error_incomplete_command[] = "FF0C0000\x0d\x0a";
static const uint8_t arygon_error_unknown_mode[] = "FF060000\x0d\x0a";
bool arygon_reset_tama (nfc_device *pnd);
int arygon_reset_tama (nfc_device *pnd);
void arygon_firmware (nfc_device *pnd, char *str);
bool
@ -135,11 +135,11 @@ arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszD
DRIVER_DATA (pnd)->abort_flag = false;
#endif
bool res = arygon_reset_tama (pnd);
int res = arygon_reset_tama (pnd);
pn53x_data_free (pnd);
nfc_device_free (pnd);
uart_close (sp);
if(!res) {
if(res < 0) {
continue;
}
@ -269,7 +269,7 @@ arygon_connect (const nfc_connstring connstring)
#endif
// Check communication using "Reset TAMA" command
if (!arygon_reset_tama(pnd)) {
if (arygon_reset_tama(pnd) < 0) {
arygon_disconnect (pnd);
return NULL;
}
@ -511,7 +511,7 @@ arygon_firmware (nfc_device *pnd, char *str)
}
}
bool
int
arygon_reset_tama (nfc_device *pnd)
{
const uint8_t arygon_reset_tama_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'r' };
@ -526,14 +526,16 @@ arygon_reset_tama (nfc_device *pnd)
res = uart_receive (DRIVER_DATA (pnd)->port, abtRx, szRx, 0, 1000);
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "No reply to 'reset TAMA' command.");
return false;
pnd->last_error = NFC_EIO;
return pnd->last_error;
}
if (0 != memcmp (abtRx, arygon_error_none, sizeof (arygon_error_none) - 1)) {
return false;
pnd->last_error = NFC_EIO;
return pnd->last_error;
}
return true;
return NFC_SUCCESS;
}
bool

View file

@ -295,8 +295,8 @@ pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, i
switch (CHIP_DATA(pnd)->power_mode) {
case LOWVBAT: {
/** PN532C106 wakeup. */
if (-1 == pn532_uart_wakeup(pnd)) {
return NFC_ECHIP;
if ((res = pn532_uart_wakeup(pnd)) < 0) {
return res;
}
// According to PN532 application note, C106 appendix: to go out Low Vbat mode and enter in normal mode we need to send a SAMConfiguration command
if ((res = pn53x_SAMConfiguration (pnd, 0x01, 500)) < 0) {
@ -305,8 +305,8 @@ pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, i
}
break;
case POWERDOWN: {
if (-1 == pn532_uart_wakeup(pnd)) {
return NFC_ECHIP;
if ((res = pn532_uart_wakeup(pnd)) < 0) {
return res;
}
}
break;
@ -362,8 +362,7 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 5, abort_p, timeout);
if (abort_p && (NFC_EOPABORTED == pnd->last_error)) {
pn532_uart_ack (pnd);
return pnd->last_error;
return pn532_uart_ack (pnd);
}
if (pnd->last_error != 0) {
@ -473,12 +472,13 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
int
pn532_uart_ack (nfc_device *pnd)
{
int res = 0;
if (POWERDOWN == CHIP_DATA(pnd)->power_mode) {
if (-1 == pn532_uart_wakeup(pnd)) {
return -1;
if ((res = pn532_uart_wakeup(pnd)) < 0) {
return res;
}
}
return (uart_send (DRIVER_DATA(pnd)->port, pn53x_ack_frame, sizeof (pn53x_ack_frame), 0) < 0) ? 0 : -1;
return (uart_send (DRIVER_DATA(pnd)->port, pn53x_ack_frame, sizeof (pn53x_ack_frame), 0));
}
bool