From e096f1f42167c339b25d448940aeb0ead61df772 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 15 Mar 2012 08:56:14 +0000 Subject: [PATCH] fix issues in spilling ndef data to stdout and fix bug in mifare-desfire-write-ndef --- examples/mifare-classic-read-ndef.c | 4 ++-- examples/mifare-desfire-create-ndef.c | 3 +-- examples/mifare-desfire-read-ndef.c | 7 +++---- examples/mifare-desfire-write-ndef.c | 6 +----- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/examples/mifare-classic-read-ndef.c b/examples/mifare-classic-read-ndef.c index 50210e1..3770d12 100644 --- a/examples/mifare-classic-read-ndef.c +++ b/examples/mifare-classic-read-ndef.c @@ -151,11 +151,11 @@ main(int argc, char *argv[]) bool read_ndef = true; if (read_options.interactive) { - printf ("Read NDEF [yN] "); + fprintf (message_stream, "Read NDEF [yN] "); fgets (buffer, BUFSIZ, stdin); read_ndef = ((buffer[0] == 'y') || (buffer[0] == 'Y')); } else { - printf ("\n"); + fprintf (message_stream, "\n"); } if (read_ndef) { diff --git a/examples/mifare-desfire-create-ndef.c b/examples/mifare-desfire-create-ndef.c index 97cc814..5bc941a 100644 --- a/examples/mifare-desfire-create-ndef.c +++ b/examples/mifare-desfire-create-ndef.c @@ -49,6 +49,7 @@ struct { void usage(char *progname) { + fprintf (stderr, "This application turns Mifare DESFire targets into NFC Forum Type 4 Tags.\n"); fprintf (stderr, "usage: %s [-y] [-K 11223344AABBCCDD]\n", progname); fprintf (stderr, "\nOptions:\n"); fprintf (stderr, " -y Do not ask for confirmation\n"); @@ -91,8 +92,6 @@ main(int argc, char *argv[]) } // Remaining args, if any, are in argv[optind .. (argc-1)] - printf ("NOTE: This application turns Mifare DESFire targets into NFC Forum Type 4 Tags.\n"); - nfc_connstring devices[8]; size_t device_count; diff --git a/examples/mifare-desfire-read-ndef.c b/examples/mifare-desfire-read-ndef.c index 7f1c3c1..4658012 100644 --- a/examples/mifare-desfire-read-ndef.c +++ b/examples/mifare-desfire-read-ndef.c @@ -53,6 +53,7 @@ struct { void usage(char *progname) { + fprintf (stderr, "This application reads a NDEF payload from a Mifare DESFire formatted as NFC Forum Type 4 Tag.\n"); fprintf (stderr, "usage: %s [-y] -o FILE [-k 11223344AABBCCDD]\n", progname); fprintf (stderr, "\nOptions:\n"); fprintf (stderr, " -y Do not ask for confirmation\n"); @@ -100,8 +101,6 @@ main(int argc, char *argv[]) } // Remaining args, if any, are in argv[optind .. (argc-1)] - printf ("NOTE: This application reads a NDEF payload from a Mifare DESFire formatted as NFC Forum Type 4 Tag.\n"); - if (ndef_output == NULL) { usage (argv[0]); exit (EXIT_FAILURE); @@ -156,11 +155,11 @@ main(int argc, char *argv[]) bool read_ndef = true; if (read_options.interactive) { - printf ("Read NDEF [yN] "); + fprintf (message_stream, "Read NDEF [yN] "); fgets (buffer, BUFSIZ, stdin); read_ndef = ((buffer[0] == 'y') || (buffer[0] == 'Y')); } else { - printf ("\n"); + fprintf (message_stream, "\n"); } if (read_ndef) { diff --git a/examples/mifare-desfire-write-ndef.c b/examples/mifare-desfire-write-ndef.c index d468205..d98b4f9 100644 --- a/examples/mifare-desfire-write-ndef.c +++ b/examples/mifare-desfire-write-ndef.c @@ -61,6 +61,7 @@ struct { void usage(char *progname) { + fprintf (stderr, "This application writes a NDEF payload into a Mifare DESFire formatted as NFC Forum Type 4 Tag.\n"); fprintf (stderr, "usage: %s [-y] -i FILE [-k 11223344AABBCCDD]\n", progname); fprintf (stderr, "\nOptions:\n"); fprintf (stderr, " -y Do not ask for confirmation\n"); @@ -108,10 +109,7 @@ main(int argc, char *argv[]) } // Remaining args, if any, are in argv[optind .. (argc-1)] - printf ("NOTE: This application writes a NDEF payload into a Mifare DESFire formatted as NFC Forum Type 4 Tag.\n"); - if (ndef_input == NULL) { - ndef_msg = (uint8_t*)ndef_default_msg; ndef_msg_len = sizeof(ndef_default_msg) + 2; if (!(ndef_msg = malloc (ndef_msg_len))) { err (EXIT_FAILURE, "malloc"); @@ -243,8 +241,6 @@ main(int argc, char *argv[]) uint8_t file_no = cc_data[off+3]; uint16_t ndefmaxlen = (((uint16_t) cc_data[off+4]) << 8) + ((uint16_t) cc_data[off+5]); fprintf (stdout, "Max NDEF size: %i bytes\n", ndefmaxlen); - if (!(ndef_msg = malloc(ndefmaxlen))) - errx (EXIT_FAILURE, "malloc"); if (ndef_msg_len > ndefmaxlen) errx (EXIT_FAILURE, "Supplied NDEF larger than max NDEF size");