diff --git a/examples/nfc-emulate-forum-tag4.c b/examples/nfc-emulate-forum-tag4.c index 2e5502c..800ab35 100644 --- a/examples/nfc-emulate-forum-tag4.c +++ b/examples/nfc-emulate-forum-tag4.c @@ -118,11 +118,10 @@ nfcforum_tag4_io (struct nfc_emulator *emulator, const byte_t *data_in, const si print_hex (data_in, data_in_len); } - /* - * The PN532 already handle RATS - */ - if ((data_in_len == 2) && (data_in[0] == ISO144434A_RATS)) - return res; + if ((data_in_len == 2) && (data_in[0] == ISO144434A_RATS)) { + // The PN532 already handle RATS, so there is nothing to do + return res; + } if(data_in_len >= 4) { if (data_in[CLA] != 0x00) @@ -352,7 +351,9 @@ main (int argc, char *argv[]) printf ("Connected to NFC device: %s\n", pnd->acName); printf ("Emulating NDEF tag now, please touch it with a second NFC device\n"); - nfc_emulate_target (pnd, &emulator); // contains already nfc_target_init() call + if (0 != nfc_emulate_target (pnd, &emulator)) { // contains already nfc_target_init() call + nfc_perror (pnd, "nfc_emulate_target"); + } nfc_disconnect(pnd); diff --git a/libnfc/nfc-device.c b/libnfc/nfc-device.c index 019a07b..f3d04ea 100644 --- a/libnfc/nfc-device.c +++ b/libnfc/nfc-device.c @@ -41,10 +41,14 @@ nfc_device_new (void) err (EXIT_FAILURE, "nfc_device_new: malloc"); } - res->bCrc = true; - res->bPar = true; - res->bEasyFraming = true; - res->bAutoIso14443_4 = true; + // Variables initiatialization + // Note: Actually, these initialization will be overwritten while the device + // will be setup. Putting them to _false_ while the default is _true_ ensure we + // send the command to the chip + res->bCrc = false; + res->bPar = false; + res->bEasyFraming = false; + res->bAutoIso14443_4 = false; res->iLastError = 0; res->driver_data = NULL; res->chip_data = NULL; diff --git a/libnfc/nfc-emulation.c b/libnfc/nfc-emulation.c index c32b564..98bc16a 100644 --- a/libnfc/nfc-emulation.c +++ b/libnfc/nfc-emulation.c @@ -52,5 +52,5 @@ nfc_emulate_target (nfc_device_t* pnd, struct nfc_emulator *emulator) } } } - return 0; + return (res < 0) ? res : 0; } diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 93b3402..3fa5861 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -625,6 +625,7 @@ nfc_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx, c * - Crc is handled by the device (NDO_HANDLE_CRC = true) * - Parity is handled the device (NDO_HANDLE_PARITY = true) * - Cryto1 cipher is disabled (NDO_ACTIVATE_CRYPTO1 = false) + * - Auto-switching in ISO14443-4 mode is enabled (NDO_AUTO_ISO14443_4 = true) * - Easy framing is disabled (NDO_EASY_FRAMING = false) * - Invalid frames are not accepted (NDO_ACCEPT_INVALID_FRAMES = false) * - Multiple frames are not accepted (NDO_ACCEPT_MULTIPLE_FRAMES = false) @@ -649,6 +650,9 @@ nfc_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_t return false; if (!nfc_configure (pnd, NDO_HANDLE_PARITY, true)) return false; + // Activate auto ISO14443-4 switching by default + if (!nfc_configure (pnd, NDO_AUTO_ISO14443_4, true)) + return false; // Activate "easy framing" feature by default if (!nfc_configure (pnd, NDO_EASY_FRAMING, true)) return false;