From 386e08d8b31093724290fc095cdd5f0e7b9aa792 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 1 Feb 2013 20:52:49 +0100 Subject: [PATCH] Fix nfc_initiator_select_passive_target() in several utils if tag is missing --- utils/nfc-mfclassic.c | 6 +++--- utils/nfc-mfultralight.c | 4 ++-- utils/nfc-read-forum-tag3.c | 4 ++-- utils/nfc-relay-picc.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/utils/nfc-mfclassic.c b/utils/nfc-mfclassic.c index 34ed512..4547df9 100644 --- a/utils/nfc-mfclassic.c +++ b/utils/nfc-mfclassic.c @@ -282,7 +282,7 @@ read_card(int read_unlocked) // Show if the readout went well if (bFailure) { // When a failure occured we need to redo the anti-collision - if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) < 0) { + if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) <= 0) { printf("!\nError: tag was removed\n"); return false; } @@ -355,7 +355,7 @@ write_card(int write_block_zero) // Show if the readout went well if (bFailure) { // When a failure occured we need to redo the anti-collision - if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) < 0) { + if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) <= 0) { printf("!\nError: tag was removed\n"); return false; } @@ -534,7 +534,7 @@ main(int argc, const char *argv[]) printf("NFC reader: %s opened\n", nfc_device_get_name(pnd)); // Try to find a MIFARE Classic tag - if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) < 0) { + if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) <= 0) { printf("Error: no tag was found\n"); nfc_close(pnd); nfc_exit(context); diff --git a/utils/nfc-mfultralight.c b/utils/nfc-mfultralight.c index d686734..0f3cd4a 100644 --- a/utils/nfc-mfultralight.c +++ b/utils/nfc-mfultralight.c @@ -142,7 +142,7 @@ write_card(void) // Show if the readout went well if (bFailure) { // When a failure occured we need to redo the anti-collision - if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) < 0) { + if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) <= 0) { ERR("tag was removed"); return false; } @@ -228,7 +228,7 @@ main(int argc, const char *argv[]) printf("NFC device: %s opened\n", nfc_device_get_name(pnd)); // Try to find a MIFARE Ultralight tag - if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) < 0) { + if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) <= 0) { ERR("no tag was found\n"); nfc_close(pnd); nfc_exit(context); diff --git a/utils/nfc-read-forum-tag3.c b/utils/nfc-read-forum-tag3.c index f522727..088c23c 100644 --- a/utils/nfc-read-forum-tag3.c +++ b/utils/nfc-read-forum-tag3.c @@ -222,7 +222,7 @@ main(int argc, char *argv[]) int error = EXIT_SUCCESS; // Polling payload (SENSF_REQ) must be present (see NFC Digital Protol) const uint8_t *pbtSensfReq = (uint8_t *)"\x00\xff\xff\x01\x00"; - if (nfc_initiator_select_passive_target(pnd, nm, pbtSensfReq, 5, &nt) < 0) { + if (nfc_initiator_select_passive_target(pnd, nm, pbtSensfReq, 5, &nt) <= 0) { nfc_perror(pnd, "nfc_initiator_select_passive_target"); error = EXIT_FAILURE; goto error; @@ -233,7 +233,7 @@ main(int argc, char *argv[]) if (0 != memcmp(nt.nti.nfi.abtSysCode, abtNfcForumSysCode, 2)) { // Retry with special polling const uint8_t *pbtSensfReqNfcForum = (uint8_t *)"\x00\x12\xfc\x01\x00"; - if (nfc_initiator_select_passive_target(pnd, nm, pbtSensfReqNfcForum, 5, &nt) < 0) { + if (nfc_initiator_select_passive_target(pnd, nm, pbtSensfReqNfcForum, 5, &nt) <= 0) { nfc_perror(pnd, "nfc_initiator_select_passive_target"); error = EXIT_FAILURE; goto error; diff --git a/utils/nfc-relay-picc.c b/utils/nfc-relay-picc.c index 2798487..5daf23e 100644 --- a/utils/nfc-relay-picc.c +++ b/utils/nfc-relay-picc.c @@ -247,7 +247,7 @@ main(int argc, char *argv[]) .nmt = NMT_ISO14443A, .nbr = NBR_106, }; - if (nfc_initiator_select_passive_target(pndInitiator, nm, NULL, 0, &ntRealTarget) < 0) { + if (nfc_initiator_select_passive_target(pndInitiator, nm, NULL, 0, &ntRealTarget) <= 0) { printf("Error: no tag was found\n"); nfc_close(pndInitiator); nfc_exit(context);