diff --git a/examples/Makefile.am b/examples/Makefile.am index a1beec5..bf4033b 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -13,7 +13,8 @@ bin_PROGRAMS = mifare-classic-format \ mifare-desfire-format \ mifare-desfire-info \ mifare-desfire-read-ndef \ - mifare-desfire-write-ndef + mifare-desfire-write-ndef \ + mifare-ultralight-info mifare_classic_format_SOURCES = mifare-classic-format.c mifare_classic_format_LDADD = $(top_builddir)/libfreefare/libfreefare.la @@ -51,4 +52,7 @@ mifare_desfire_read_ndef_LDADD = $(top_builddir)/libfreefare/libfreefare.la mifare_desfire_write_ndef_SOURCES = mifare-desfire-write-ndef.c mifare_desfire_write_ndef_LDADD = $(top_builddir)/libfreefare/libfreefare.la +mifare_ultralight_info_SOURCES = mifare-ultralight-info.c +mifare_ultralight_info_LDADD = $(top_builddir)/libfreefare/libfreefare.la + CLEANFILES= *.gcno diff --git a/examples/mifare-ultralight-info.c b/examples/mifare-ultralight-info.c new file mode 100644 index 0000000..f27aabc --- /dev/null +++ b/examples/mifare-ultralight-info.c @@ -0,0 +1,78 @@ +/*- + * Copyright (C) 2012, Romain Tartiere. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see + * + * $Id$ + */ +#include +#include + +#include + +#include + +int +main (int argc, char *argv[]) +{ + int error = EXIT_SUCCESS; + nfc_device *device = NULL; + MifareTag *tags = NULL; + + if (argc > 1) + errx (EXIT_FAILURE, "usage: %s", argv[0]); + + nfc_connstring devices[8]; + size_t device_count; + + nfc_init (NULL); + + device_count = nfc_list_devices (NULL, devices, sizeof (devices) / sizeof (*devices)); + if (device_count <= 0) + errx (EXIT_FAILURE, "No NFC device found"); + + for (size_t d = 0; d < device_count; d++) { + if (!(device = nfc_open (NULL, devices[d]))) { + warnx ("nfc_open() failed."); + error = EXIT_FAILURE; + continue; + } + + if (!(tags = freefare_get_tags (device))) { + nfc_close (device); + errx (EXIT_FAILURE, "Error listing tags."); + } + + for (int i = 0; (!error) && tags[i]; i++) { + switch (freefare_get_tag_type (tags[i])) { + case ULTRALIGHT: + case ULTRALIGHT_C: + break; + default: + continue; + } + + char *tag_uid = freefare_get_tag_uid (tags[i]); + printf ("Tag with UID %s is a %s\n", tag_uid, freefare_get_tag_friendly_name (tags[i])); + + free (tag_uid); + } + + freefare_free_tags (tags); + nfc_close (device); + } + + nfc_exit (NULL); + exit(error); +}