less structs and defines publicly exposed

- nfc_device is now an opaque type;
 - PN53x specific errors are not public anymore;
 - nfc_device_name() renamed to nfc_device_get_name() for the sake of consistency;
 - examples/*, utils/* uses the new nfc_device_get_name() function instead of access directly to struct's content;
 - new error defined: NFC_ERFTRANS for notifying about RF transmission error, its used by mifare.c to detect permissions error on mifare;
 - drivers initiator_transceive_bytes() function now returns libnfc's error code on failure (<0), and received bytes count on success (>=0);
 - remove some unused errors.
This commit is contained in:
Romuald Conty 2011-12-19 00:23:21 +00:00
parent 9bdc20353c
commit bf7c36d9bb
29 changed files with 162 additions and 178 deletions

View file

@ -175,7 +175,7 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
printf ("Connected to NFC reader: %s\n\n", pnd->acName);
printf ("Connected to NFC reader: %s\n\n", nfc_device_get_name (pnd));
// Send the 7 bits request command specified in ISO 14443A (0x26)
if (!transmit_bits (abtReqa, 7)) {

View file

@ -77,7 +77,7 @@ main (int argc, const char *argv[])
printf("Unable to connect to NFC device.\n");
return EXIT_FAILURE;
}
printf ("Connected to NFC device: %s\n", pnd->acName);
printf ("Connected to NFC device: %s\n", nfc_device_get_name (pnd));
signal (SIGINT, stop_dep_communication);

View file

@ -111,7 +111,7 @@ main (int argc, const char *argv[])
printf("Unable to connect to NFC device.\n");
return EXIT_FAILURE;
}
printf ("Connected to NFC device: %s\n", pnd->acName);
printf ("Connected to NFC device: %s\n", nfc_device_get_name (pnd));
signal (SIGINT, stop_dep_communication);

View file

@ -189,7 +189,7 @@ main(int argc, char *argv[])
exit (EXIT_FAILURE);
}
printf ("Connected to NFC device: %s\n", pnd->acName);
printf ("Connected to NFC device: %s\n", nfc_device_get_name (pnd));
printf ("Emulating NDEF tag now, please touch it with a second NFC device\n");
if (nfc_emulate_target (pnd, &emulator) < 0) {

View file

@ -191,7 +191,7 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
printf ("Connected to NFC device: %s\n", pnd->acName);
printf ("Connected to NFC device: %s\n", nfc_device_get_name (pnd));
// Notes for ISO14443-A emulated tags:
// * Only short UIDs are supported

View file

@ -134,7 +134,7 @@ main (int argc, char *argv[])
}
printf ("\n");
printf ("Connected to NFC device: %s\n", pnd->acName);
printf ("Connected to NFC device: %s\n", nfc_device_get_name (pnd));
printf ("[+] Try to break out the auto-emulation, this requires a second NFC device!\n");
printf ("[+] To do this, please send any command after the anti-collision\n");
printf ("[+] For example, send a RATS command or use the \"nfc-anticol\" or \"nfc-list\" tool.\n");

View file

@ -101,19 +101,18 @@ main (int argc, const char *argv[])
nfc_initiator_init (pnd);
printf ("Connected to NFC reader: %s\n", pnd->acName);
printf ("Connected to NFC reader: %s\n", nfc_device_get_name (pnd));
printf ("NFC device will poll during %ld ms (%u pollings of %lu ms for %zd modulations)\n", (unsigned long) uiPollNr * szModulations * uiPeriod * 150, uiPollNr, (unsigned long) uiPeriod * 150, szModulations);
res = nfc_initiator_poll_target (pnd, nmModulations, szModulations, uiPollNr, uiPeriod, &nt);
if (res) {
if ((res = nfc_initiator_poll_target (pnd, nmModulations, szModulations, uiPollNr, uiPeriod, &nt)) < 0) {
nfc_perror (pnd, "nfc_initiator_poll_targets");
nfc_disconnect (pnd);
exit (EXIT_FAILURE);
}
if (res > 0) {
print_nfc_target ( nt, verbose );
} else {
if (pnd->iLastError) {
nfc_perror (pnd, "nfc_initiator_poll_targets");
nfc_disconnect (pnd);
exit (EXIT_FAILURE);
} else {
printf ("No target found.\n");
}
printf ("No target found.\n");
}
nfc_disconnect (pnd);
exit (EXIT_SUCCESS);

View file

@ -125,7 +125,7 @@ main (int argc, char *argv[])
printf ("Hint: tag <---> initiator (relay) <---> target (relay) <---> original reader\n\n");
printf ("Connected to the NFC emulator device: %s\n", pndTag->acName);
printf ("Connected to the NFC emulator device: %s\n", nfc_device_get_name (pndTag));
printf ("[+] Try to break out the auto-emulation, this requires a second reader!\n");
printf ("[+] To do this, please send any command after the anti-collision\n");
printf ("[+] For example, send a RATS command or use the \"nfc-anticol\" tool\n");
@ -162,7 +162,7 @@ main (int argc, char *argv[])
// Try to open the NFC reader
pndReader = nfc_connect (connstrings[1]);
printf ("Connected to the NFC reader device: %s", pndReader->acName);
printf ("Connected to the NFC reader device: %s", nfc_device_get_name (pndReader));
printf ("%s", "Configuring NFC reader settings...");
nfc_initiator_init (pndReader);
if ((nfc_device_set_property_bool (pndReader, NP_HANDLE_CRC, false) < 0) ||

View file

@ -86,7 +86,7 @@ main (int argc, const char *argv[])
return EXIT_FAILURE;
}
printf ("NFC device [%s] connected.\n", pnd->acName);
printf ("NFC device [%s] connected.\n", nfc_device_get_name (pnd));
result = pn53x_transceive (pnd, pncmd_diagnose_communication_line_test, sizeof (pncmd_diagnose_communication_line_test), abtRx, &szRx, 0);
if (result) {

View file

@ -89,7 +89,7 @@ main (int argc, const char *argv[])
return EXIT_FAILURE;
}
printf ("Connected to NFC device: %s\n", pnd->acName);
printf ("Connected to NFC device: %s\n", nfc_device_get_name (pnd));
// Print the example's menu
printf ("\nSelect the communication mode:\n");

View file

@ -94,7 +94,7 @@ int main(int argc, const char* argv[])
return EXIT_FAILURE;
}
printf ("Connected to NFC reader: %s\n", pnd->acName);
printf ("Connected to NFC reader: %s\n", nfc_device_get_name (pnd));
nfc_initiator_init(pnd);
char *cmd;

View file

@ -116,54 +116,9 @@ extern "C" {
#define NFC_EOVFLOW -5 // Buffer overflow
#define NFC_EOPABORTED -6 // Operation aborted (by user)
#define NFC_ECHIP -7 // Device's internal chip error
#define NFC_EDEVNOTSUPP -8 // Operation not supported by device
#define NFC_ENOTIMPL -9 // Not (yet) implemented
/* PN53x specific errors */
// TODO: Be not PN53x-specific here
#define ETIMEOUT 0x01
#define ECRC 0x02
#define EPARITY 0x03
#define EBITCOUNT 0x04
#define EFRAMING 0x05
#define EBITCOLL 0x06
#define ESMALLBUF 0x07
#define EBUFOVF 0x09
#define ERFTIMEOUT 0x0a
#define ERFPROTO 0x0b
#define EOVHEAT 0x0d
#define EINBUFOVF 0x0e
#define EINVPARAM 0x10
#define EDEPUNKCMD 0x12
#define EINVRXFRAM 0x13
#define EMFAUTH 0x14
#define ENSECNOTSUPP 0x18 // PN533 only
#define EBCC 0x23
#define EDEPINVSTATE 0x25
#define EOPNOTALL 0x26
#define ECMD 0x27
#define ETGREL 0x29
#define ECID 0x2a
#define ECDISCARDED 0x2b
#define ENFCID3 0x2c
#define EOVCURRENT 0x2d
#define ENAD 0x2e
/* PN53x framing-level errors */
#define EFRAACKMISMATCH 0x0100 /* Unexpected data */
#define EFRAISERRFRAME 0x0101 /* Error frame */
/* Communication-level errors */
#define ECOMIO 0x1000 /* Input/output error */
#define ECOMTIMEOUT 0x1001 /* Operation timeout */
/* Software level errors */
#define ETGUIDNOTSUP 0xFF00 /* Target UID not supported */
#define EOPABORT 0xFF01 /* Operation aborted */
#define EINVALARG 0xFF02 /* Invalid argument */
#define EDEVNOTSUP 0xFF03 /* Not supported by device */
#define ENOTIMPL 0xFF04 /* Not (yet) implemented in libnfc */
#define NFC_ERFTRANS -8 // Error while RF transmission
#define NFC_EDEVNOTSUPP -9 // Operation not supported by device
#define NFC_ENOTIMPL -10 // Not (yet) implemented
# ifdef __cplusplus
}

View file

@ -284,31 +284,31 @@ select:
// Read error
if (res < 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "RX error.");
return ECOMIO;
return NFC_EIO;
}
// Read time-out
if (res == 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Timeout!");
return ECOMTIMEOUT;
return NFC_ETIMEOUT;
}
if (FD_ISSET (iAbortFd, &rfds)) {
// Abort requested
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Abort!");
close (iAbortFd);
return EOPABORT;
return NFC_EOPABORTED;
}
// Retrieve the count of the incoming bytes
res = ioctl (UART_DATA(sp)->fd, FIONREAD, &available_bytes_count);
if (res != 0) {
return ECOMIO;
return NFC_EIO;
}
// There is something available, read the data
res = read (UART_DATA(sp)->fd, pbtRx + received_bytes_count, MIN(available_bytes_count, (expected_bytes_count - received_bytes_count)));
// Stop if the OS has some troubles reading the data
if (res <= 0) {
return ECOMIO;
return NFC_EIO;
}
received_bytes_count += res;
@ -330,7 +330,7 @@ uart_send (serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout)
if ((int) szTx == write (UART_DATA(sp)->fd, pbtTx, szTx))
return 0;
else
return ECOMIO;
return NFC_EIO;
}
char **

View file

@ -299,6 +299,34 @@ typedef struct {
#define PN53X_SFR_P7CFGB 0xFFF5
#define PN53X_SFR_P7 0xFFF7
/* PN53x specific errors */
#define ETIMEOUT 0x01
#define ECRC 0x02
#define EPARITY 0x03
#define EBITCOUNT 0x04
#define EFRAMING 0x05
#define EBITCOLL 0x06
#define ESMALLBUF 0x07
#define EBUFOVF 0x09
#define ERFTIMEOUT 0x0a
#define ERFPROTO 0x0b
#define EOVHEAT 0x0d
#define EINBUFOVF 0x0e
#define EINVPARAM 0x10
#define EDEPUNKCMD 0x12
#define EINVRXFRAM 0x13
#define EMFAUTH 0x14
#define ENSECNOTSUPP 0x18 // PN533 only
#define EBCC 0x23
#define EDEPINVSTATE 0x25
#define EOPNOTALL 0x26
#define ECMD 0x27
#define ETGREL 0x29
#define ECID 0x2a
#define ECDISCARDED 0x2b
#define ENFCID3 0x2c
#define EOVCURRENT 0x2d
#define ENAD 0x2e
#ifdef LOGGING
static const pn53x_register pn53x_registers[] = {

View file

@ -892,7 +892,8 @@ pn53x_initiator_init (struct nfc_device *pnd)
// Configure the PN53X to be an Initiator or Reader/Writer
if (!pn53x_write_register (pnd, PN53X_REG_CIU_Control, SYMBOL_INITIATOR, 0x10))
return NFC_DEVICE_ERROR;
// FIXMES pn53x_write_register() should return integer
return NFC_EIO;
CHIP_DATA (pnd)->operating_mode = INITIATOR;
return NFC_SUCCESS;
@ -911,7 +912,7 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
if (nm.nmt == NMT_ISO14443BI || nm.nmt == NMT_ISO14443B2SR || nm.nmt == NMT_ISO14443B2CT) {
if (CHIP_DATA(pnd)->type == RCS360) {
// TODO add support for RC-S360, at the moment it refuses to send raw frames without a first select
pnd->last_error = ENOTIMPL;
pnd->last_error = NFC_ENOTIMPL;
return false;
}
// No native support in InListPassiveTarget so we do discovery by hand
@ -986,7 +987,7 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
const pn53x_modulation pm = pn53x_nm_to_pm(nm);
if (PM_UNDEFINED == pm) {
pnd->last_error = EINVALARG;
pnd->last_error = NFC_EINVARG;
return false;
}
@ -1174,7 +1175,7 @@ pn53x_initiator_transceive_bits (struct nfc_device *pnd, const uint8_t *pbtTx, c
return true;
}
bool
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)
{
@ -1184,7 +1185,7 @@ pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx,
// We can not just send bytes without parity if while the PN53X expects we handled them
if (!pnd->bPar) {
pnd->last_error = NFC_EINVARG;
return false;
return pnd->last_error;
}
// Copy the data into the command frame
@ -1200,15 +1201,25 @@ 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
if (!pn53x_set_tx_bits (pnd, 0))
return false;
if (!pn53x_set_tx_bits (pnd, 0)) {
pnd->last_error = NFC_EIO; // FIXME pn53x_set_tx_bits should return an integer
return pnd->last_error;
}
// Send the frame to the PN53X chip and get the answer
// We have to give the amount of bytes + (the two command bytes 0xD4, 0x42)
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
size_t szRx = sizeof(abtRx);
if (!pn53x_transceive (pnd, abtCmd, szTx + szExtraTxLen, abtRx, &szRx, timeout))
return false;
if (!pn53x_transceive (pnd, abtCmd, szTx + szExtraTxLen, abtRx, &szRx, timeout)) {
// FIXME pn53x_transceive should return an integer
if (CHIP_DATA (pnd)->last_status_byte == EINVRXFRAM) {
pnd->last_error = NFC_ERFTRANS;
return pnd->last_error;
} else {
pnd->last_error = NFC_EIO;
return pnd->last_error;
}
}
if (pbtRx != NULL) {
// Save the received byte count
@ -1217,8 +1228,8 @@ pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx,
// Copy the received bytes
memcpy (pbtRx, abtRx + 1, *pszRx);
}
// Everything went successful
return true;
// Everything went successful, we return received bytes count
return *pszRx;
}
void __pn53x_init_timer(struct nfc_device *pnd, const uint32_t max_cycles)
@ -1413,13 +1424,13 @@ pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uint8_t *p
// We can not just send bytes without parity while the PN53X expects we handled them
if (!pnd->bPar) {
CHIP_DATA(pnd)->last_status_byte = EINVALARG;
pnd->last_error = NFC_EINVARG;
return false;
}
// Sorry, no easy framing support
// TODO to be changed once we'll provide easy framing support from libnfc itself...
if (pnd->bEasyFraming) {
CHIP_DATA(pnd)->last_status_byte = ENOTIMPL;
pnd->last_error = NFC_ENOTIMPL;
return false;
}
@ -1528,7 +1539,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size
case NMT_ISO14443A:
ptm = PTM_PASSIVE_ONLY;
if ((pnt->nti.nai.abtUid[0] != 0x08) || (pnt->nti.nai.szUidLen != 4)) {
CHIP_DATA(pnd)->last_status_byte = ETGUIDNOTSUP;
pnd->last_error = NFC_EINVARG;
return false;
}
pn53x_set_parameters (pnd, PARAM_AUTO_ATR_RES, false);
@ -1557,7 +1568,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size
case NMT_ISO14443B2SR:
case NMT_ISO14443B2CT:
case NMT_JEWEL:
CHIP_DATA(pnd)->last_status_byte = EDEVNOTSUP;
pnd->last_error = NFC_EDEVNOTSUPP;
return false;
break;
}
@ -1659,7 +1670,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size
case NMT_ISO14443B2SR:
case NMT_ISO14443B2CT:
case NMT_JEWEL:
CHIP_DATA(pnd)->last_status_byte = EDEVNOTSUP;
pnd->last_error = NFC_EDEVNOTSUPP;
return false;
break;
}
@ -1792,7 +1803,7 @@ pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszR
break;
} else {
// TODO Support EasyFraming for other cases by software
CHIP_DATA(pnd)->last_status_byte = ENOTIMPL;
pnd->last_error = NFC_ENOTIMPL;
return false;
}
}
@ -1883,7 +1894,7 @@ pn53x_target_send_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const siz
break;
} else {
// TODO Support EasyFraming for other cases by software
CHIP_DATA(pnd)->last_status_byte = ENOTIMPL;
pnd->last_error = NFC_ENOTIMPL;
return false;
}
}
@ -1920,7 +1931,6 @@ static struct sErrorMessage {
{ EBITCOLL, "Bit-collision" }, // An abnormal bit-collision has been detected during bit wise anti-collision at 106 kbps
{ ESMALLBUF, "Communication Buffer Too Small" }, // Communication buffer size insufficient
{ EBUFOVF, "Buffer Overflow" }, // RF Buffer overflow has been detected by the CIU (bit BufferOvfl of the register CIU_Error)
{ ERFTIMEOUT, "RF Timeout" }, // In active communication mode, the RF field has not been switched on in time by the counterpart (as defined in NFCIP-1 standard)
{ ERFPROTO, "RF Protocol Error" }, // RF Protocol error (see PN53x manual)
{ EOVHEAT, "Chip Overheating" }, // Temperature error: the internal temperature sensor has detected overheating, and therefore has automatically switched off the antenna drivers
{ EINBUFOVF, "Internal Buffer overflow."}, // Internal buffer overflow
@ -1929,6 +1939,7 @@ static struct sErrorMessage {
{ ECMD, "Command Not Acceptable" }, // Command is not acceptable due to the current context
{ EOVCURRENT, "Over Current" },
/* DEP errors */
{ ERFTIMEOUT, "RF Timeout" }, // In active communication mode, the RF field has not been switched on in time by the counterpart (as defined in NFCIP-1 standard)
{ EDEPUNKCMD, "Unknown DEP Command" },
{ EDEPINVSTATE, "Invalid DEP State" }, // DEP Protocol: Invalid device state, the system is in a state which does not allow the operation
{ ENAD, "NAD Missing in DEP Frame" },
@ -1942,19 +1953,6 @@ static struct sErrorMessage {
{ ECID, "Card ID Mismatch" }, // ISO14443 type B: Card ID mismatch, meaning that the expected card has been exchanged with another one.
{ ECDISCARDED, "Card Discarded" }, // ISO/IEC14443 type B: the card previously activated has disappeared.
{ ENFCID3, "NFCID3 Mismatch" },
/* Software level errors */
{ ETGUIDNOTSUP, "Target UID not supported" }, // In target mode, PN53x only support 4 bytes UID and the first byte must start with 0x08
{ EOPABORT, "Operation aborted" }, // Error used to catch a user-requested command abort
{ EINVALARG, "Invalid argument" }, // Function called with invalid argument(s)
{ ENOTIMPL, "Not (yet) implemented in library" },
/* Framming-level errors */
{ EFRAACKMISMATCH, "Expected ACK frame" },
{ EFRAISERRFRAME, "Received an error frame" },
/* Communication-level errors */
{ ECOMIO, "Input/output error" }, // Communication I/O errors: connection broken, read/write failure, unreacheable device, etc.
{ ECOMTIMEOUT, "Operation timed-out" }, // A timeout occured while reading device's reply
/* Device-level errors */
{ EDEVNOTSUP, "Operation not supported by device" } // Requested task can not be done by current device
};
const char *
@ -2039,7 +2037,7 @@ pn53x_SAMConfiguration (struct nfc_device *pnd, const pn532_sam_mode ui8Mode, in
if (CHIP_DATA(pnd)->type != PN532) {
// This function is not supported by pn531 neither pn533
CHIP_DATA(pnd)->last_status_byte = EDEVNOTSUP;
pnd->last_error = NFC_EDEVNOTSUPP;
return false;
}
@ -2054,7 +2052,7 @@ pn53x_SAMConfiguration (struct nfc_device *pnd, const pn532_sam_mode ui8Mode, in
szCmd = 3;
break;
default:
CHIP_DATA(pnd)->last_status_byte = EINVALARG;
pnd->last_error = NFC_EINVARG;
return false;
}
return (pn53x_transceive (pnd, abtCmd, szCmd, NULL, NULL, timeout));
@ -2101,14 +2099,14 @@ pn53x_InListPassiveTarget (struct nfc_device *pnd,
case PM_ISO14443B_106:
if (!(pnd->btSupportByte & SUPPORT_ISO14443B)) {
// Eg. Some PN532 doesn't support type B!
CHIP_DATA(pnd)->last_status_byte = EDEVNOTSUP;
pnd->last_error = NFC_EDEVNOTSUPP;
return false;
}
break;
case PM_JEWEL_106:
if(CHIP_DATA(pnd)->type == PN531) {
// These modulations are not supported by pn531
CHIP_DATA(pnd)->last_status_byte = EDEVNOTSUP;
pnd->last_error = NFC_EDEVNOTSUPP;
return false;
}
break;
@ -2117,12 +2115,12 @@ pn53x_InListPassiveTarget (struct nfc_device *pnd,
case PM_ISO14443B_847:
if((CHIP_DATA(pnd)->type != PN533) || (!(pnd->btSupportByte & SUPPORT_ISO14443B))) {
// These modulations are not supported by pn531 neither pn532
CHIP_DATA(pnd)->last_status_byte = EDEVNOTSUP;
pnd->last_error = NFC_EDEVNOTSUPP;
return false;
}
break;
default:
CHIP_DATA(pnd)->last_status_byte = EINVALARG;
pnd->last_error = NFC_EINVARG;
return false;
}
abtCmd[2] = pmInitModulation; // BrTy, the type of init modulation used for polling a passive tag
@ -2186,7 +2184,7 @@ pn53x_InAutoPoll (struct nfc_device *pnd,
{
if (CHIP_DATA(pnd)->type != PN532) {
// This function is not supported by pn531 neither pn533
CHIP_DATA(pnd)->last_status_byte = EDEVNOTSUP;
pnd->last_error = NFC_EDEVNOTSUPP;
return false;
}
@ -2268,7 +2266,7 @@ pn53x_InJumpForDEP (struct nfc_device *pnd,
break;
case NBR_847:
case NBR_UNDEFINED:
CHIP_DATA(pnd)->last_status_byte = EINVALARG;
pnd->last_error = NFC_EINVARG;
return false;
break;
}
@ -2288,7 +2286,7 @@ pn53x_InJumpForDEP (struct nfc_device *pnd,
break;
case NBR_847:
case NBR_UNDEFINED:
CHIP_DATA(pnd)->last_status_byte = EINVALARG;
pnd->last_error = NFC_EINVARG;
return false;
break;
}
@ -2417,7 +2415,7 @@ pn53x_check_ack_frame (struct nfc_device *pnd, const uint8_t *pbtRxFrame, const
return true;
}
}
CHIP_DATA(pnd)->last_status_byte = EFRAACKMISMATCH;
pnd->last_error = NFC_EIO;
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unexpected PN53x reply!");
return false;
}
@ -2428,7 +2426,7 @@ pn53x_check_error_frame (struct nfc_device *pnd, const uint8_t *pbtRxFrame, cons
if (szRxFrameLen >= sizeof (pn53x_error_frame)) {
if (0 == memcmp (pbtRxFrame, pn53x_error_frame, sizeof (pn53x_error_frame))) {
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "PN53x sent an error frame");
CHIP_DATA(pnd)->last_status_byte = EFRAISERRFRAME;
pnd->last_error = NFC_EIO;
return false;
}
}

View file

@ -302,7 +302,7 @@ bool pn53x_initiator_select_dep_target (struct nfc_device *pnd,
bool pn53x_initiator_transceive_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits,
const uint8_t *pbtTxPar, uint8_t *pbtRx, size_t *pszRxBits,
uint8_t *pbtRxPar);
bool 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);
bool pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits,
const uint8_t *pbtTxPar, uint8_t *pbtRx, size_t *pszRxBits,

View file

@ -380,32 +380,32 @@ arygon_tama_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen,
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 5, abort_p, timeout);
if (abort_p && (EOPABORT == pnd->last_error)) {
if (abort_p && (NFC_EOPABORTED == pnd->last_error)) {
arygon_abort (pnd);
/* last_error got reset by arygon_abort() */
pnd->last_error = EOPABORT;
return -1;
pnd->last_error = NFC_EOPABORTED;
return pnd->last_error;
}
if (pnd->last_error != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
return -1;
return pnd->last_error;
}
const uint8_t pn53x_preamble[3] = { 0x00, 0x00, 0xff };
if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch");
pnd->last_error = ECOMIO;
return -1;
pnd->last_error = NFC_EIO;
return pnd->last_error;
}
if ((0x01 == abtRxBuf[3]) && (0xff == abtRxBuf[4])) {
// Error frame
uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 3, 0, timeout);
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Application level error detected");
pnd->last_error = EFRAISERRFRAME;
return -1;
pnd->last_error = NFC_EIO;
return pnd->last_error;
} else if ((0xff == abtRxBuf[3]) && (0xff == abtRxBuf[4])) {
// Extended frame
// ARYGON devices does not support extended frame sending
@ -415,8 +415,8 @@ arygon_tama_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen,
if (256 != (abtRxBuf[3] + abtRxBuf[4])) {
// TODO: Retry
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
pnd->last_error = ECOMIO;
return -1;
pnd->last_error = NFC_EIO;
return pnd->last_error;
}
// abtRxBuf[3] (LEN) include TFI + (CC+1)
@ -425,7 +425,7 @@ arygon_tama_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen,
if (len > szDataLen) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
@ -438,13 +438,13 @@ arygon_tama_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen,
if (abtRxBuf[0] != 0xD5) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "TFI Mismatch");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
if (abtRxBuf[1] != CHIP_DATA (pnd)->ui8LastCommand + 1) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Command Code verification failed");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
@ -470,13 +470,13 @@ arygon_tama_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen,
if (btDCS != abtRxBuf[0]) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Data checksum mismatch");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
if (0x00 != abtRxBuf[1]) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame postamble mismatch");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
// The PN53x command is done and we successfully received the reply

View file

@ -321,7 +321,7 @@ pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, i
size_t szFrame = 0;
if (!pn53x_build_frame (abtFrame, &szFrame, pbtData, szData)) {
pnd->last_error = EINVALARG;
pnd->last_error = NFC_EINVARG;
return false;
}
@ -363,20 +363,20 @@ 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 && (EOPABORT == pnd->last_error)) {
if (abort_p && (NFC_EOPABORTED == pnd->last_error)) {
pn532_uart_ack (pnd);
return -1;
return pnd->last_error;
}
if (pnd->last_error != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
return -1;
return pnd->last_error;
}
const uint8_t pn53x_preamble[3] = { 0x00, 0x00, 0xff };
if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
@ -384,8 +384,8 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
// Error frame
uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 3, 0, timeout);
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Application level error detected");
pnd->last_error = EFRAISERRFRAME;
return -1;
pnd->last_error = NFC_EIO;
return pnd->last_error;
} else if ((0xff == abtRxBuf[3]) && (0xff == abtRxBuf[4])) {
// Extended frame
pnd->last_error = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 3, 0, timeout);
@ -396,7 +396,7 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
if (((abtRxBuf[0] + abtRxBuf[1] + abtRxBuf[2]) % 256) != 0) {
// TODO: Retry
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
} else {
@ -404,7 +404,7 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
if (256 != (abtRxBuf[3] + abtRxBuf[4])) {
// TODO: Retry
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
@ -414,7 +414,7 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
if (len > szDataLen) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
@ -427,13 +427,13 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
if (abtRxBuf[0] != 0xD5) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "TFI Mismatch");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
if (abtRxBuf[1] != CHIP_DATA (pnd)->ui8LastCommand + 1) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Command Code verification failed");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
@ -459,13 +459,13 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
if (btDCS != abtRxBuf[0]) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Data checksum mismatch");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
if (0x00 != abtRxBuf[1]) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame postamble mismatch");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
// The PN53x command is done and we successfully received the reply

View file

@ -516,14 +516,14 @@ pn53x_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, co
int res = pn53x_usb_bulk_write (DRIVER_DATA (pnd), abtFrame, szFrame, timeout);
if (res < 0) {
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return false;
}
uint8_t abtRxBuf[PN53X_USB_BUFFER_LEN];
res = pn53x_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf), timeout);
if (res < 0) {
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
// try to interrupt current device state
pn53x_usb_ack(pnd);
return false;
@ -541,7 +541,7 @@ pn53x_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, co
// 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 < 0) {
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
// try to interrupt current device state
pn53x_usb_ack(pnd);
return false;
@ -574,7 +574,7 @@ read:
// A user-provided timeout is set, we have to cut it in multiple chunk to be able to keep an nfc_abort_command() mecanism
remaining_time -= USB_TIMEOUT_PER_PASS;
if (remaining_time <= 0) {
pnd->last_error = ECOMTIMEOUT;
pnd->last_error = NFC_ETIMEOUT;
return -1;
} else {
usb_timeout = MIN(remaining_time, USB_TIMEOUT_PER_PASS);
@ -587,7 +587,7 @@ read:
if (DRIVER_DATA (pnd)->abort_flag) {
DRIVER_DATA (pnd)->abort_flag = false;
pn53x_usb_ack (pnd);
pnd->last_error = EOPABORT;
pnd->last_error = NFC_EOPABORTED;
return -1;
} else {
goto read;
@ -595,7 +595,7 @@ read:
}
if (res < 0) {
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
// try to interrupt current device state
pn53x_usb_ack(pnd);
return -1;
@ -604,7 +604,7 @@ read:
const uint8_t pn53x_preamble[3] = { 0x00, 0x00, 0xff };
if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
offset += 3;
@ -612,7 +612,7 @@ read:
if ((0x01 == abtRxBuf[offset]) && (0xff == abtRxBuf[offset + 1])) {
// Error frame
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Application level error detected");
pnd->last_error = EFRAISERRFRAME;
pnd->last_error = NFC_EIO;
return -1;
} else if ((0xff == abtRxBuf[offset]) && (0xff == abtRxBuf[offset + 1])) {
// Extended frame
@ -623,7 +623,7 @@ read:
if (((abtRxBuf[offset] + abtRxBuf[offset + 1] + abtRxBuf[offset + 2]) % 256) != 0) {
// TODO: Retry
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
offset += 3;
@ -632,7 +632,7 @@ read:
if (256 != (abtRxBuf[offset] + abtRxBuf[offset + 1])) {
// TODO: Retry
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
@ -643,21 +643,21 @@ read:
if (len > szDataLen) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
// TFI + PD0 (CC+1)
if (abtRxBuf[offset] != 0xD5) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "TFI Mismatch");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
offset += 1;
if (abtRxBuf[offset] != CHIP_DATA (pnd)->ui8LastCommand + 1) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Command Code verification failed");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
offset += 1;
@ -673,14 +673,14 @@ read:
if (btDCS != abtRxBuf[offset]) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Data checksum mismatch");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
offset += 1;
if (0x00 != abtRxBuf[offset]) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame postamble mismatch");
pnd->last_error = ECOMIO;
pnd->last_error = NFC_EIO;
return -1;
}
// The PN53x command is done and we successfully received the reply

View file

@ -137,7 +137,7 @@ struct nfc_driver_t {
bool (*initiator_poll_target) (struct nfc_device *pnd, const nfc_modulation * pnmModulations, const size_t szModulations, const uint8_t uiPollNr, const uint8_t btPeriod, nfc_target * pnt);
bool (*initiator_select_dep_target) (struct nfc_device *pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info * pndiInitiator, nfc_target * pnt, const int timeout);
bool (*initiator_deselect_target) (struct nfc_device *pnd);
bool (*initiator_transceive_bytes) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, int timeout);
int (*initiator_transceive_bytes) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, int timeout);
bool (*initiator_transceive_bits) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar);
bool (*initiator_transceive_bytes_timed) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, uint32_t * cycles);
bool (*initiator_transceive_bits_timed) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar, uint32_t * cycles);

View file

@ -799,7 +799,7 @@ nfc_perror (const nfc_device *pnd, const char *pcString)
* @return Returns a string with the device name
*/
const char *
nfc_device_name (nfc_device *pnd)
nfc_device_get_name (nfc_device *pnd)
{
return pnd->acName;
}

View file

@ -94,28 +94,32 @@ nfc_initiator_mifare_cmd (nfc_device *pnd, const mifare_cmd mc, const uint8_t ui
if (szParamLen)
memcpy (abtCmd + 2, (uint8_t *) pmp, szParamLen);
bEasyFraming = pnd->bEasyFraming;
// FIXME: Save and restore bEasyFraming
// bEasyFraming = nfc_device_get_property_bool (pnd, NP_EASY_FRAMING, &bEasyFraming);
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, true) < 0) {
nfc_perror (pnd, "nfc_device_set_property_bool");
return false;
}
// Fire the mifare command
if (!nfc_initiator_transceive_bytes (pnd, abtCmd, 2 + szParamLen, abtRx, &szRx, 0)) {
if (pnd->iLastError == EINVRXFRAM) {
// "Invalid received frame" AKA EINVRXFRAM, usual means we are
int res;
if ((res = nfc_initiator_transceive_bytes (pnd, abtCmd, 2 + szParamLen, abtRx, &szRx, -1)) < 0) {
if (res == NFC_ERFTRANS) {
// "Invalid received frame", usual means we are
// authenticated on a sector but the requested MIFARE cmd (read, write)
// is not permitted by current acces bytes;
// So there is nothing to do here.
} else {
nfc_perror (pnd, "nfc_initiator_transceive_bytes");
}
nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, bEasyFraming);
// XXX nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, bEasyFraming);
return false;
}
/* XXX
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, bEasyFraming) < 0) {
nfc_perror (pnd, "nfc_device_set_property_bool");
return false;
}
*/
// When we have executed a read command, copy the received bytes into the param
if (mc == MC_READ) {

View file

@ -356,7 +356,7 @@ main (int argc, char *argv[])
signal (SIGINT, stop_emulation);
printf ("Connected to NFC device: %s\n", pnd->acName);
printf ("Connected to NFC device: %s\n", nfc_device_get_name(pnd));
printf ("Emulating NDEF tag now, please touch it with a second NFC device\n");
if (0 != nfc_emulate_target (pnd, &emulator)) { // contains already nfc_target_init() call

View file

@ -117,7 +117,7 @@ main (int argc, const char *argv[])
}
nfc_initiator_init (pnd);
printf ("Connected to NFC device: %s\n", pnd->acName);
printf ("Connected to NFC device: %s\n", nfc_device_get_name (pnd));
nfc_modulation nm;

View file

@ -554,7 +554,7 @@ main (int argc, const char *argv[])
// Disable ISO14443-4 switching in order to read devices that emulate Mifare Classic with ISO14443-4 compliance.
nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, false);
printf ("Connected to NFC reader: %s\n", pnd->acName);
printf ("Connected to NFC reader: %s\n", nfc_device_get_name (pnd));
// Try to find a MIFARE Classic tag
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt)) {

View file

@ -204,7 +204,7 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
printf ("Connected to NFC reader: %s\n\n", pnd->acName);
printf ("Connected to NFC reader: %s\n", nfc_device_get_name (pnd));
// Send the 7 bits request command specified in ISO 14443A (0x26)
if (!transmit_bits (abtReqa, 7)) {

View file

@ -219,7 +219,7 @@ main (int argc, const char *argv[])
exit (EXIT_FAILURE);
}
printf ("Connected to NFC device: %s\n", pnd->acName);
printf ("Connected to NFC device: %s\n", nfc_device_get_name (pnd));
// Try to find a MIFARE Ultralight tag
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt)) {

View file

@ -202,7 +202,7 @@ main(int argc, char *argv[])
exit (EXIT_FAILURE);
}
fprintf (message_stream, "Connected to NFC device: %s\n", pnd->acName);
fprintf (message_stream, "Connected to NFC device: %s\n", nfc_device_get_name (pnd));
nfc_modulation nm = {
.nmt = NMT_FELICA,

View file

@ -227,7 +227,7 @@ main (int argc, char *argv[])
exit(EXIT_FAILURE);
}
printf ("Connected to the NFC reader device: %s\n", pndInitiator->acName);
printf ("Connected to the NFC reader device: %s\n", nfc_device_get_name (pndInitiator));
if (nfc_initiator_init (pndInitiator) < 0) {
printf ("Error: fail initializing initiator\n");
@ -352,7 +352,7 @@ main (int argc, char *argv[])
return EXIT_FAILURE;
}
printf ("Connected to the NFC emulator device: %s\n", pndTarget->acName);
printf ("Connected to the NFC emulator device: %s\n", nfc_device_get_name (pndTarget));
if (!nfc_target_init (pndTarget, &ntEmulatedTarget, abtCapdu, &szCapduLen)) {
ERR ("%s", "Initialization of NFC emulator failed");