timmerk / nfc-tools

Automatically exported from code.google.com/p/nfc-tools
0 stars 0 forks source link

Improve mifare_ultralight_get_uid method #20

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I had some problems with this function, when I tried to continuously 
searching for tags. Maybe its better if libfreefare do it in this way:

char *
mifare_ultralight_get_uid (MifareTag tag)
{
    char *uid = malloc (2 * 7 + 1);

    snprintf(uid, 15, "%02x%02x%02x%02x%02x%02x%02x", 
    tag->info.abtUid[1], tag->info.abtUid[2], tag->info.abtUid[3], tag-
>info.abtUid[4],
    tag->info.abtUid[5], tag->info.abtUid[6], tag->info.abtUid[7]);
    uid[14] = '\0';
    return uid;
} 

Original issue reported on code.google.com by rose...@gmail.com on 9 Mar 2010 at 2:19

GoogleCodeExporter commented 9 years ago
Hello,

You're right, it is better to retrieve UID from a tag without reading 
physically the
tag and fortunatelly you already have this data in tag structure.

Original comment by romu...@libnfc.org on 9 Mar 2010 at 3:12

GoogleCodeExporter commented 9 years ago
BTW, could you described what you experiment when you are saying:
"some problems with this function, when I tried to continuously searching for 
tags"

What kind of problem ? What happends ?
I'm asking because i'm not sure that changing this method will avoid all 
problems if
its related to reading when continuously searching for tag.

Original comment by romu...@libnfc.org on 9 Mar 2010 at 3:17

GoogleCodeExporter commented 9 years ago
Hi Roel,

So I search for tag in loop, in the first I get MifareTag and saves it, then in 
the 
next loops I get new MifareTag and compare UIDs from the old tag with the new 
one. If 
I find new Tag (UID don't equals) I save new MifareTag. The problem was with 
Mifare 
Ultraligth, because when I put this tag into the field, old and new UIDs don't 
equals. I get similar UIDs but not the same.  

If you'd like I could send you code, when I'll back from work :) 

Original comment by rose...@gmail.com on 10 Mar 2010 at 8:16

GoogleCodeExporter commented 9 years ago
Ops... sorry Rconty, I clicked on the wrong email on your profile :P

Original comment by rose...@gmail.com on 10 Mar 2010 at 8:29

GoogleCodeExporter commented 9 years ago
D'oh!  Must think before I code!  I take it!

Original comment by romain.t...@gmail.com on 30 Mar 2010 at 1:10

GoogleCodeExporter commented 9 years ago
Hum, actualy, a Mifare UltraLight UID is 7 byte long but you select it 
providing a 8 byte long UID.

e.g. nfc-list reports:

    ATQA (SENS_RES): 00  44  
       UID (NFCID1): 88  04  99  9c  99  6d  02  80  
      SAK (SEL_RES): 00  

mifare_ultralight_connect use 0x8804999c996d0280 to select the tag, but it's 
UID is 0x04999c996d0280 (no 
trailling 0x88)...

Original comment by romain.t...@gmail.com on 30 Mar 2010 at 1:45

GoogleCodeExporter commented 9 years ago
Temporary fix has been committed at r203.  I don't close this since I really 
think refactoring is required to have a 
unique freefare_get_tag_uid().  Still thinking about it though...

Original comment by romain.t...@gmail.com on 30 Mar 2010 at 2:01

GoogleCodeExporter commented 9 years ago
0x88 is a special code called CT to cascade UID:
This is an NXP trick to allow to select 4 bytes UID same way we select 7 bytes 
UID:
CT (Cascade Tag) byte (88), signals that the UID is not complete yet.

Have a look at 
http://code.google.com/p/libnfc/source/browse/trunk/src/lib/nfc.c#405

Original comment by romu...@libnfc.org on 30 Mar 2010 at 2:41

GoogleCodeExporter commented 9 years ago
Okay, I am happy with r205!

rosek86, take note that you will need libnfc from at least r328 to have this 
working in libfreefare.

Original comment by romain.t...@gmail.com on 30 Mar 2010 at 4:27