From 0b42cbfb8f9dfd21b7ddb5c3a409a19d995967f1 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Mon, 27 Jun 2011 09:14:19 +0000 Subject: [PATCH] examples/nfc-emulate-forum-tag4: this example now fails with ENOTSUPP when used with a non-PN532 chip. --- examples/nfc-emulate-forum-tag4.c | 20 ++++++++++---------- libnfc/chips/pn53x.c | 6 ++++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/nfc-emulate-forum-tag4.c b/examples/nfc-emulate-forum-tag4.c index 800ab35..9b99ec3 100644 --- a/examples/nfc-emulate-forum-tag4.c +++ b/examples/nfc-emulate-forum-tag4.c @@ -112,17 +112,17 @@ nfcforum_tag4_io (struct nfc_emulator *emulator, const byte_t *data_in, const si struct nfcforum_tag4_ndef_data *ndef_data = (struct nfcforum_tag4_ndef_data *)(emulator->user_data); struct nfcforum_tag4_state_machine_data *state_machine_data = (struct nfcforum_tag4_state_machine_data *)(emulator->state_machine->data); + if (data_in_len == 0) { + // No input data, nothing to do + return res; + } + // Show transmitted command if (!quiet_output) { printf (" In: "); print_hex (data_in, data_in_len); } - 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) return -ENOTSUP; @@ -168,7 +168,6 @@ nfcforum_tag4_io (struct nfc_emulator *emulator, const byte_t *data_in, const si return -ENOTSUP; } - break; case ISO7816_READ_BINARY: if ((size_t)(data_in[LC] + 2) > data_out_len) { @@ -210,11 +209,12 @@ nfcforum_tag4_io (struct nfc_emulator *emulator, const byte_t *data_in, const si // Show transmitted command if (!quiet_output) { - printf (" Out: "); - if (res < 0) - printf ("No data (returning with an error %d)\n", res); - else + if (res < 0) { + ERR ("%s (%d)", strerror (-res), -res); + } else { + printf (" Out: "); print_hex (data_out, res); + } } return res; } diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 4c76775..8099765 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -1629,6 +1629,12 @@ pn53x_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_ } CHIP_DATA (pnd)->current_target = malloc (sizeof(nfc_target_t)); memcpy (CHIP_DATA (pnd)->current_target, pnt, sizeof(nfc_target_t)); + + if (ptm & PTM_ISO14443_4_PICC_ONLY) { + // When PN532 is in PICC target mode, it automatically reply to RATS so + // we don't need to forward this command + *pszRx = 0; + } } }