diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index efe418e..2e2a9ee 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -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 diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 4f0aa43..f47aeed 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -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