From 0d4744001a393aaf1df1c545e80b440993f8aebe Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Mon, 1 Mar 2010 14:04:47 +0000 Subject: [PATCH] Add support for friendly tag names. --- examples/mifare-classic-format.c | 2 +- libfreefare/freefare.c | 21 +++++++++++++++++---- libfreefare/freefare.h | 1 + libfreefare/freefare_internal.h | 1 + 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/examples/mifare-classic-format.c b/examples/mifare-classic-format.c index daff854..6da47a1 100644 --- a/examples/mifare-classic-format.c +++ b/examples/mifare-classic-format.c @@ -122,7 +122,7 @@ main(int argc, char *argv[]) char *tag_uid = mifare_classic_get_uid (tags[i]); char buffer[BUFSIZ]; - printf ("Found MIFARE Classic %s. Format [yN] ", tag_uid); + printf ("Found %s with UID %s. Format [yN] ", freefare_get_tag_friendly_name (tags[i]), tag_uid); fgets (buffer, BUFSIZ, stdin); bool format = ((buffer[0] == 'y') || (buffer[0] == 'Y')); diff --git a/libfreefare/freefare.c b/libfreefare/freefare.c index 616d169..e6b9025 100644 --- a/libfreefare/freefare.c +++ b/libfreefare/freefare.c @@ -26,13 +26,14 @@ struct supported_tag { uint8_t ATQA[2], SAK; enum mifare_tag_type type; + const char *friendly_name; }; struct supported_tag supported_tags[] = { - { { 0x00, 0x44 }, 0x00, ULTRALIGHT }, - { { 0x00, 0x04 }, 0x08, CLASSIC_1K }, - { { 0x00, 0x02 }, 0x18, CLASSIC_4K }, - { { 0x00, 0x02 }, 0x38, CLASSIC_4K }, /* Emulated */ + { { 0x00, 0x44 }, 0x00, ULTRALIGHT, "Mifare UltraLight" }, + { { 0x00, 0x04 }, 0x08, CLASSIC_1K, "Mifare Classic 1k" }, + { { 0x00, 0x02 }, 0x18, CLASSIC_4K, "Mifare Classic 4k" }, + { { 0x00, 0x02 }, 0x38, CLASSIC_4K, "Mifare Classic 4k (Emulated)" }, }; @@ -81,6 +82,7 @@ freefare_get_tags (nfc_device_t *device) bool found = false; enum mifare_tag_type type; + const char *friendly_name; for (int i = 0; i < sizeof (supported_tags) / sizeof (struct supported_tag); i++) { if ((target_info.nai.abtAtqa[0] == supported_tags[i].ATQA[0]) && @@ -88,6 +90,7 @@ freefare_get_tags (nfc_device_t *device) (target_info.nai.btSak == supported_tags[i].SAK)) { type = supported_tags[i].type; + friendly_name = supported_tags[i].friendly_name; found = true; break; } @@ -127,6 +130,7 @@ freefare_get_tags (nfc_device_t *device) (tags[tag_count-1])->info = target_info.nai; (tags[tag_count-1])->active = 0; (tags[tag_count-1])->type = type; + (tags[tag_count-1])->friendly_name = friendly_name; tags[tag_count] = NULL; nfc_initiator_deselect_tag (device); @@ -144,6 +148,15 @@ freefare_get_tag_type (MifareTag tag) return tag->type; } +/* + * Returns the friendly name of the provided tag. + */ +const char * +freefare_get_tag_friendly_name (MifareTag tag) +{ + return tag->friendly_name; +} + /* * Free the provided tag list. */ diff --git a/libfreefare/freefare.h b/libfreefare/freefare.h index 105cc7c..f49b7ff 100644 --- a/libfreefare/freefare.h +++ b/libfreefare/freefare.h @@ -53,6 +53,7 @@ typedef unsigned char MifareUltralightPage[4]; MifareTag *freefare_get_tags (nfc_device_t *device); enum mifare_tag_type freefare_get_tag_type (MifareTag tag); +const char *freefare_get_tag_friendly_name (MifareTag tag); void freefare_free_tags (MifareTag *tags); int mifare_ultralight_connect (MifareTag tag); diff --git a/libfreefare/freefare_internal.h b/libfreefare/freefare_internal.h index 4abe4f2..1a7a691 100644 --- a/libfreefare/freefare_internal.h +++ b/libfreefare/freefare_internal.h @@ -63,6 +63,7 @@ struct mifare_tag { nfc_device_t *device; nfc_iso14443a_info_t info; enum mifare_tag_type type; + const char *friendly_name; int active; };