libnfc/drivers: pn532_uart_ack() and arygon_reset_tama() functions return now libnfc error code on failure.
This commit is contained in:
parent
c30e9eed36
commit
5d4f22c548
2 changed files with 19 additions and 17 deletions
|
@ -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_incomplete_command[] = "FF0C0000\x0d\x0a";
|
||||||
static const uint8_t arygon_error_unknown_mode[] = "FF060000\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);
|
void arygon_firmware (nfc_device *pnd, char *str);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -135,11 +135,11 @@ arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszD
|
||||||
DRIVER_DATA (pnd)->abort_flag = false;
|
DRIVER_DATA (pnd)->abort_flag = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool res = arygon_reset_tama (pnd);
|
int res = arygon_reset_tama (pnd);
|
||||||
pn53x_data_free (pnd);
|
pn53x_data_free (pnd);
|
||||||
nfc_device_free (pnd);
|
nfc_device_free (pnd);
|
||||||
uart_close (sp);
|
uart_close (sp);
|
||||||
if(!res) {
|
if(res < 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,7 +269,7 @@ arygon_connect (const nfc_connstring connstring)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Check communication using "Reset TAMA" command
|
// Check communication using "Reset TAMA" command
|
||||||
if (!arygon_reset_tama(pnd)) {
|
if (arygon_reset_tama(pnd) < 0) {
|
||||||
arygon_disconnect (pnd);
|
arygon_disconnect (pnd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -511,7 +511,7 @@ arygon_firmware (nfc_device *pnd, char *str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
int
|
||||||
arygon_reset_tama (nfc_device *pnd)
|
arygon_reset_tama (nfc_device *pnd)
|
||||||
{
|
{
|
||||||
const uint8_t arygon_reset_tama_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'r' };
|
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);
|
res = uart_receive (DRIVER_DATA (pnd)->port, abtRx, szRx, 0, 1000);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "No reply to 'reset TAMA' command.");
|
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)) {
|
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
|
bool
|
||||||
|
|
|
@ -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) {
|
switch (CHIP_DATA(pnd)->power_mode) {
|
||||||
case LOWVBAT: {
|
case LOWVBAT: {
|
||||||
/** PN532C106 wakeup. */
|
/** PN532C106 wakeup. */
|
||||||
if (-1 == pn532_uart_wakeup(pnd)) {
|
if ((res = pn532_uart_wakeup(pnd)) < 0) {
|
||||||
return NFC_ECHIP;
|
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
|
// 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) {
|
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;
|
break;
|
||||||
case POWERDOWN: {
|
case POWERDOWN: {
|
||||||
if (-1 == pn532_uart_wakeup(pnd)) {
|
if ((res = pn532_uart_wakeup(pnd)) < 0) {
|
||||||
return NFC_ECHIP;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
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);
|
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 5, abort_p, timeout);
|
||||||
|
|
||||||
if (abort_p && (NFC_EOPABORTED == pnd->last_error)) {
|
if (abort_p && (NFC_EOPABORTED == pnd->last_error)) {
|
||||||
pn532_uart_ack (pnd);
|
return pn532_uart_ack (pnd);
|
||||||
return pnd->last_error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pnd->last_error != 0) {
|
if (pnd->last_error != 0) {
|
||||||
|
@ -473,12 +472,13 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
|
||||||
int
|
int
|
||||||
pn532_uart_ack (nfc_device *pnd)
|
pn532_uart_ack (nfc_device *pnd)
|
||||||
{
|
{
|
||||||
|
int res = 0;
|
||||||
if (POWERDOWN == CHIP_DATA(pnd)->power_mode) {
|
if (POWERDOWN == CHIP_DATA(pnd)->power_mode) {
|
||||||
if (-1 == pn532_uart_wakeup(pnd)) {
|
if ((res = pn532_uart_wakeup(pnd)) < 0) {
|
||||||
return -1;
|
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
|
bool
|
||||||
|
|
Loading…
Add table
Reference in a new issue