fix some last_error with result of previous function.

This commit is contained in:
Audrey Diacre 2012-01-12 13:52:48 +00:00
parent cc8d4f68ab
commit 0e2c60d0fa
5 changed files with 24 additions and 33 deletions

View file

@ -1244,6 +1244,7 @@ pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx,
{ {
size_t szExtraTxLen; size_t szExtraTxLen;
uint8_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; uint8_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
int res = 0;
// We can not just send bytes without parity if while the PN53X expects we handled them // We can not just send bytes without parity if while the PN53X expects we handled them
if (!pnd->bPar) { if (!pnd->bPar) {
@ -1264,8 +1265,8 @@ pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx,
} }
// To transfer command frames bytes we can not have any leading bits, reset this to zero // To transfer command frames bytes we can not have any leading bits, reset this to zero
if (pn53x_set_tx_bits (pnd, 0) < 0) { if ((res = pn53x_set_tx_bits (pnd, 0)) < 0) {
pnd->last_error = NFC_EIO; // FIXME pn53x_set_tx_bits should return an integer pnd->last_error = res;
return pnd->last_error; return pnd->last_error;
} }
@ -1273,16 +1274,10 @@ pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx,
// We have to give the amount of bytes + (the two command bytes 0xD4, 0x42) // We have to give the amount of bytes + (the two command bytes 0xD4, 0x42)
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
size_t szRx = sizeof(abtRx); size_t szRx = sizeof(abtRx);
int res = 0;
if ((res = pn53x_transceive (pnd, abtCmd, szTx + szExtraTxLen, abtRx, szRx, timeout)) < 0) { if ((res = pn53x_transceive (pnd, abtCmd, szTx + szExtraTxLen, abtRx, szRx, timeout)) < 0) {
// FIXME pn53x_transceive should return an integer pnd->last_error = res;
if (CHIP_DATA (pnd)->last_status_byte == EINVRXFRAM) {
pnd->last_error = NFC_ERFTRANS;
return pnd->last_error; return pnd->last_error;
} else {
pnd->last_error = NFC_EIO;
return pnd->last_error;
}
} }
szRx = (size_t) res; szRx = (size_t) res;
if (pbtRx != NULL) { if (pbtRx != NULL) {

View file

@ -299,7 +299,7 @@ int pn53x_initiator_select_dep_target (struct nfc_device *pnd,
const int timeout); const int timeout);
int pn53x_initiator_transceive_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, int pn53x_initiator_transceive_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits,
const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar); const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar);
int pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx,
uint8_t *pbtRx, size_t *pszRx, int timeout); uint8_t *pbtRx, size_t *pszRx, int timeout);
int pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, int pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits,
const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles); const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles);

View file

@ -306,6 +306,7 @@ arygon_disconnect (nfc_device *pnd)
int int
arygon_tama_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout) arygon_tama_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout)
{ {
int res = 0;
// Before sending anything, we need to discard from any junk bytes // Before sending anything, we need to discard from any junk bytes
uart_flush_input (DRIVER_DATA(pnd)->port); uart_flush_input (DRIVER_DATA(pnd)->port);
@ -319,23 +320,21 @@ arygon_tama_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData,
return pnd->last_error; return pnd->last_error;
} }
if (pn53x_build_frame (abtFrame + 1, &szFrame, pbtData, szData) < 0) { if ((res = pn53x_build_frame (abtFrame + 1, &szFrame, pbtData, szData)) < 0) {
pnd->last_error = NFC_EINVARG; pnd->last_error = res;
return pnd->last_error; return pnd->last_error;
} }
int res = uart_send (DRIVER_DATA (pnd)->port, abtFrame, szFrame + 1, timeout); if ((res = uart_send (DRIVER_DATA (pnd)->port, abtFrame, szFrame + 1, timeout)) != 0) {
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)"); log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)");
pnd->last_error = NFC_EIO; pnd->last_error = res;
return pnd->last_error; return pnd->last_error;
} }
uint8_t abtRxBuf[6]; uint8_t abtRxBuf[6];
res = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, sizeof (abtRxBuf), 0, timeout); if ((res = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, sizeof (abtRxBuf), 0, timeout)) != 0) {
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to read ACK"); log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to read ACK");
pnd->last_error = NFC_EIO; pnd->last_error = res;
return pnd->last_error; return pnd->last_error;
} }
@ -526,7 +525,7 @@ 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.");
pnd->last_error = NFC_EIO; pnd->last_error = res;
return pnd->last_error; return pnd->last_error;
} }

View file

@ -318,8 +318,8 @@ pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, i
uint8_t abtFrame[PN532_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" uint8_t abtFrame[PN532_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
size_t szFrame = 0; size_t szFrame = 0;
if (pn53x_build_frame (abtFrame, &szFrame, pbtData, szData) < 0) { if ((res = pn53x_build_frame (abtFrame, &szFrame, pbtData, szData)) < 0) {
pnd->last_error = NFC_EINVARG; pnd->last_error = res;
return pnd->last_error; return pnd->last_error;
} }

View file

@ -510,20 +510,18 @@ pn53x_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, co
{ {
uint8_t abtFrame[PN53X_USB_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" uint8_t abtFrame[PN53X_USB_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
size_t szFrame = 0; size_t szFrame = 0;
int res = 0;
pn53x_build_frame (abtFrame, &szFrame, pbtData, szData); pn53x_build_frame (abtFrame, &szFrame, pbtData, szData);
int res = pn53x_usb_bulk_write (DRIVER_DATA (pnd), abtFrame, szFrame, timeout); if ((res = pn53x_usb_bulk_write (DRIVER_DATA (pnd), abtFrame, szFrame, timeout)) < 0) {
pnd->last_error = res;
if (res < 0) {
pnd->last_error = NFC_EIO;
return pnd->last_error; return pnd->last_error;
} }
uint8_t abtRxBuf[PN53X_USB_BUFFER_LEN]; uint8_t abtRxBuf[PN53X_USB_BUFFER_LEN];
res = pn53x_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf), timeout); if ((res = pn53x_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf), timeout)) < 0) {
if (res < 0) { pnd->last_error = res;
pnd->last_error = NFC_EIO;
// try to interrupt current device state // try to interrupt current device state
pn53x_usb_ack(pnd); pn53x_usb_ack(pnd);
return pnd->last_error; return pnd->last_error;
@ -539,9 +537,8 @@ pn53x_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, co
// pn53x_usb_receive()) will be able to retreive the correct response // pn53x_usb_receive()) will be able to retreive the correct response
// packet. // packet.
// FIXME Sony reader is also affected by this bug but NACK is not supported // FIXME Sony reader is also affected by this bug but NACK is not supported
int res = pn53x_usb_bulk_write (DRIVER_DATA (pnd), (uint8_t *)pn53x_nack_frame, sizeof(pn53x_nack_frame), timeout); if ((res = pn53x_usb_bulk_write (DRIVER_DATA (pnd), (uint8_t *)pn53x_nack_frame, sizeof(pn53x_nack_frame), timeout)) < 0) {
if (res < 0) { pnd->last_error = res;
pnd->last_error = NFC_EIO;
// try to interrupt current device state // try to interrupt current device state
pn53x_usb_ack(pnd); pn53x_usb_ack(pnd);
return pnd->last_error; return pnd->last_error;
@ -595,7 +592,7 @@ read:
} }
if (res < 0) { if (res < 0) {
pnd->last_error = NFC_EIO; pnd->last_error = res;
// try to interrupt current device state // try to interrupt current device state
pn53x_usb_ack(pnd); pn53x_usb_ack(pnd);
return pnd->last_error; return pnd->last_error;