From e27446a8f8c470cc7a41cfeec1e6ffe4f23478e0 Mon Sep 17 00:00:00 2001 From: cbdev Date: Thu, 22 Jun 2023 01:11:31 +0200 Subject: Basic NTAG support --- reader.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'reader.c') diff --git a/reader.c b/reader.c index f37ade4..0ca56cf 100644 --- a/reader.c +++ b/reader.c @@ -86,6 +86,24 @@ int reader_init(){ return reader_init_backend(); } +static void reader_print_tag(nfc_tag_info_t tag){ + size_t n = 0; + char* type = "UNST"; + switch(tag.type){ + case tag_unset: type = "UNST"; break; + case tag_unknown: type = "UNKN"; break; + case tag_mifare1: type = "MFR1"; break; + case tag_ntag: type = "NTAG"; break; + case tag_desfire: type = "DESF"; break; + } + + printf("[%s", type); + for(n = 0; n < tag.uid_length; n++){ + printf(" %02X", tag.uid[n]); + } + printf("]"); +} + static void reader_expire(){ size_t n = 0; for(n = 0; n < MAX_TAGS; n++){ @@ -101,16 +119,22 @@ static int reader_process(){ //new tag tags[n].flags |= FLAG_ACTIVE; if(tags[n].flags & FLAG_TAG_LOCKED){ - printf("A tag was detected (slot %lu), but no key is known\n", n); + printf("Slot %2lu: ", n); + reader_print_tag(tags[n].info); + printf(" locked, unusable\n"); return 0; } if(tags[n].flags & FLAG_TAG_UNPROGRAMMED){ - printf("Unprogrammed tag detected (slot %lu)\n", n); + printf("Slot %2lu: ", n); + reader_print_tag(tags[n].info); + printf(" unprogrammed\n"); //TODO return 0; } if(tags[n].flags & FLAG_TAG_DATA_VALID){ - printf("Command tag detected (slot %lu)\n", n); + printf("Slot %2lu: ", n); + reader_print_tag(tags[n].info); + printf(" valid\n"); //TODO return 0; } @@ -136,7 +160,7 @@ int reader_tag_present(uint8_t flags, nfc_tag_info_t tag){ size_t n = 0; //sanitize input flags - flags &= (FLAG_TAG_DATA_VALID | FLAG_TAG_UNPROGRAMMED | FLAG_TAG_LOCKED); + flags &= (TAG_STATUS_FLAGS); //check if tag already known for(n = 0; n < MAX_TAGS; n++){ -- cgit v1.2.3