enhance new error handling
- add accessor to last error occured - add new public error NFC_ETGRELEASED (Target Released)
This commit is contained in:
parent
125553c72e
commit
93b34fa70b
3 changed files with 64 additions and 11 deletions
|
@ -93,6 +93,7 @@ extern "C" {
|
||||||
NFC_EXPORT const char *nfc_strerror (const nfc_device *pnd);
|
NFC_EXPORT const char *nfc_strerror (const nfc_device *pnd);
|
||||||
NFC_EXPORT int nfc_strerror_r (const nfc_device *pnd, char *buf, size_t buflen);
|
NFC_EXPORT int nfc_strerror_r (const nfc_device *pnd, char *buf, size_t buflen);
|
||||||
NFC_EXPORT void nfc_perror (const nfc_device *pnd, const char *s);
|
NFC_EXPORT void nfc_perror (const nfc_device *pnd, const char *s);
|
||||||
|
NFC_EXPORT int nfc_device_get_last_error (const nfc_device *pnd);
|
||||||
|
|
||||||
/* Special data accessors */
|
/* Special data accessors */
|
||||||
NFC_EXPORT const char *nfc_device_get_name (nfc_device *pnd);
|
NFC_EXPORT const char *nfc_device_get_name (nfc_device *pnd);
|
||||||
|
@ -111,14 +112,15 @@ extern "C" {
|
||||||
#define NFC_SUCCESS 0 // No error
|
#define NFC_SUCCESS 0 // No error
|
||||||
#define NFC_EIO -1 // Input / output error, device will not be usable anymore
|
#define NFC_EIO -1 // Input / output error, device will not be usable anymore
|
||||||
#define NFC_EINVARG -2 // Invalid argument(s)
|
#define NFC_EINVARG -2 // Invalid argument(s)
|
||||||
#define NFC_ENOTSUCHDEV -3 // No such device
|
#define NFC_EDEVNOTSUPP -3 // Operation not supported by device
|
||||||
#define NFC_ETIMEOUT -4 // Operation timed out
|
#define NFC_ENOTSUCHDEV -4 // No such device
|
||||||
#define NFC_EOVFLOW -5 // Buffer overflow
|
#define NFC_EOVFLOW -5 // Buffer overflow
|
||||||
#define NFC_EOPABORTED -6 // Operation aborted (by user)
|
#define NFC_ETIMEOUT -6 // Operation timed out
|
||||||
#define NFC_ECHIP -7 // Device's internal chip error
|
#define NFC_EOPABORTED -7 // Operation aborted (by user)
|
||||||
#define NFC_ERFTRANS -8 // Error while RF transmission
|
#define NFC_ENOTIMPL -8 // Not (yet) implemented
|
||||||
#define NFC_EDEVNOTSUPP -9 // Operation not supported by device
|
#define NFC_ETGRELEASED -10 // Target released
|
||||||
#define NFC_ENOTIMPL -10 // Not (yet) implemented
|
#define NFC_ERFTRANS -20 // Error while RF transmission
|
||||||
|
#define NFC_ECHIP -90 // Device's internal chip error
|
||||||
|
|
||||||
# ifdef __cplusplus
|
# ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,10 +198,52 @@ pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szT
|
||||||
}
|
}
|
||||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Last command status: %s", pn53x_strerror(pnd));
|
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Last command status: %s", pn53x_strerror(pnd));
|
||||||
|
|
||||||
if (CHIP_DATA(pnd)->last_status_byte)
|
switch (CHIP_DATA(pnd)->last_status_byte) {
|
||||||
return NFC_ECHIP;
|
case 0:
|
||||||
|
res = NFC_SUCCESS;
|
||||||
|
break;
|
||||||
|
case ETIMEOUT:
|
||||||
|
case ECRC:
|
||||||
|
case EPARITY:
|
||||||
|
case EBITCOUNT:
|
||||||
|
case EFRAMING:
|
||||||
|
case EBITCOLL:
|
||||||
|
case ERFPROTO:
|
||||||
|
case ERFTIMEOUT:
|
||||||
|
case EDEPUNKCMD:
|
||||||
|
case EDEPINVSTATE:
|
||||||
|
case ENAD:
|
||||||
|
case ENFCID3:
|
||||||
|
case EINVRXFRAM:
|
||||||
|
case EBCC:
|
||||||
|
case ECID:
|
||||||
|
res = NFC_ERFTRANS;
|
||||||
|
break;
|
||||||
|
case ESMALLBUF:
|
||||||
|
case EOVCURRENT:
|
||||||
|
case EBUFOVF:
|
||||||
|
case EOVHEAT:
|
||||||
|
case EINBUFOVF:
|
||||||
|
res = NFC_ECHIP;
|
||||||
|
break;
|
||||||
|
case EINVPARAM:
|
||||||
|
case EOPNOTALL:
|
||||||
|
case ECMD:
|
||||||
|
case ENSECNOTSUPP:
|
||||||
|
res = NFC_EINVARG;
|
||||||
|
break;
|
||||||
|
case ETGREL:
|
||||||
|
case ECDISCARDED:
|
||||||
|
res = NFC_ETGRELEASED;
|
||||||
|
default:
|
||||||
|
res = NFC_ECHIP;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
/*
|
||||||
|
{ EMFAUTH, "Mifare Authentication Error" },
|
||||||
|
*/
|
||||||
|
|
||||||
return ((0 == CHIP_DATA(pnd)->last_status_byte) ? NFC_SUCCESS : NFC_ECHIP);
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
11
libnfc/nfc.c
11
libnfc/nfc.c
|
@ -433,7 +433,7 @@ nfc_initiator_poll_target (nfc_device *pnd,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Select a target and request active or passive mode for D.E.P. (Data Exchange Protocol)
|
* @brief Select a target and request active or passive mode for D.E.P. (Data Exchange Protocol)
|
||||||
* @return Returns selected D.E.P tagets count on success, otherwise returns libnfc's error code (negative value).
|
* @return Returns selected D.E.P targets count on success, otherwise returns libnfc's error code (negative value).
|
||||||
*
|
*
|
||||||
* @param pnd \a nfc_device struct pointer that represent currently used device
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||||
* @param ndm desired D.E.P. mode (\a NDM_ACTIVE or \a NDM_PASSIVE for active, respectively passive mode)
|
* @param ndm desired D.E.P. mode (\a NDM_ACTIVE or \a NDM_PASSIVE for active, respectively passive mode)
|
||||||
|
@ -791,6 +791,15 @@ nfc_perror (const nfc_device *pnd, const char *pcString)
|
||||||
fprintf (stderr, "%s: %s\n", pcString, nfc_strerror (pnd));
|
fprintf (stderr, "%s: %s\n", pcString, nfc_strerror (pnd));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns last error occured on a nfc_device
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
nfc_device_get_last_error (const nfc_device *pnd)
|
||||||
|
{
|
||||||
|
return pnd->last_error;
|
||||||
|
}
|
||||||
|
|
||||||
/* Special data accessors */
|
/* Special data accessors */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue