From 03da46df659e69717d397622e7d2e76ed3cb5675 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Wed, 4 Aug 2010 16:11:09 +0000 Subject: [PATCH] Enforce target type identification with ATS comparison. --- libfreefare/freefare.c | 15 +++++++++------ libfreefare/freefare_internal.h | 4 +++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/libfreefare/freefare.c b/libfreefare/freefare.c index aa60dda..fee6c39 100644 --- a/libfreefare/freefare.c +++ b/libfreefare/freefare.c @@ -18,17 +18,18 @@ */ #include +#include #include #include "freefare_internal.h" struct supported_tag supported_tags[] = { - { 0x08, CLASSIC_1K, "Mifare Classic 1k" }, - { 0x18, CLASSIC_4K, "Mifare Classic 4k" }, - { 0x38, CLASSIC_4K, "Mifare Classic 4k (Emulated)" }, - { 0x20, DESFIRE, "Mifare DESFire 4k" }, - { 0x00, ULTRALIGHT, "Mifare UltraLight" }, + { CLASSIC_1K, "Mifare Classic 1k", 0x08, 0, { 0x00 } }, + { CLASSIC_4K, "Mifare Classic 4k", 0x18, 0, { 0x00 } }, + { CLASSIC_4K, "Mifare Classic 4k (Emulated)", 0x38, 0, { 0x00 } }, + { DESFIRE, "Mifare DESFire 4k", 0x20, 5, { 0x75, 0x77, 0x81, 0x02, 0x80 }}, + { ULTRALIGHT, "Mifare UltraLight", 0x00, 0, { 0x00 } }, }; @@ -79,7 +80,9 @@ freefare_get_tags (nfc_device_t *device) struct supported_tag *tag_info; for (size_t i = 0; i < sizeof (supported_tags) / sizeof (struct supported_tag); i++) { - if (target_info.nai.btSak == supported_tags[i].SAK) { + if ((target_info.nai.btSak == supported_tags[i].SAK) && + (target_info.nai.szAtsLen == supported_tags[i].ATS_length) && + (0 == memcmp (target_info.nai.abtAts, supported_tags[i].ATS, supported_tags[i].ATS_length))) { tag_info = &(supported_tags[i]); found = true; diff --git a/libfreefare/freefare_internal.h b/libfreefare/freefare_internal.h index af3bfc2..225c29e 100644 --- a/libfreefare/freefare_internal.h +++ b/libfreefare/freefare_internal.h @@ -99,9 +99,11 @@ void *assert_crypto_buffer_size (MifareTag tag, size_t nbytes); #define MIFARE_ULTRALIGHT_PAGE_COUNT 16 struct supported_tag { - uint8_t SAK; enum mifare_tag_type type; const char *friendly_name; + uint8_t SAK; + uint8_t ATS_length; + uint8_t ATS[5]; }; /*