Reading correct data from NFC wrist band with NXP

2019-02-28 08:08发布

I am very new to NFC devices reading but I have managed to implement in my own project using the code from nfc-mfultralight.c (libnfc).

What I don't understand is that when I read the data from a MIFARE Ultralight band, I get lots of garbage.

For example, I have the number 255555574558888 in the tag (I used an Android device to write this number to the tag).

Now when I run:

nfc-mfultralight r /home/user/dump

I get this

d▒r▒!▒ H▒▒U255555574558888▒-67644-67546-2346

This is from the examples of libnfc, so shouldn't this program just read the correct data? The Android app I am using just sees the value 255555574558888. The value -67644-67546-2346 is part of what I had written before.

How do I know just the correct data I need to read? What should I change in the example code so that it works correctly?

I am using an ACR122 to read the data from the tags.

PS: This is my first project with NFC devices, libnfc and MIFARE Ultralight tags, so any things you think I should read please do tell me.

Edit 1

So I have found this question: Reading a NFC Mifare card with NXP Reader Library

Which I think helps me out a bit. I printed out the hex value of another test string and got this

04  64  13  fb
72  f7  21  84 
20  48  00  00
e1  11  06  00 
03  0a  d1  01
06  54  02  65 
6e  68  65  79
fe  00  00  79 
35  35  38  38
38  38  fe  00 
2d  36  37  36
34  34  2d  36 
37  35  34  36
2d  32  33  34
36  fe  00  00
00  00  00  00
00

I see the 3d followed by 0a and then d1, but what is all the values before the 3d? Is this something because of libnfc?

1条回答
小情绪 Triste *
2楼-- · 2019-02-28 08:31

The data you are seing in pages 0 and 1 (bytes 0 to 7) is the card's UID. Page 2 contains card-specific data (bytes 8 and 9) and the lock bytes (bytes 10 and 11). Page 3 contains the Capability Container (CC) that indicates that this tag is formatted according to the NFC Forum Type 2 tag operation specification version 1.1. The user data area of the tag starts at page 4.

As this tag follows the NFC Forum's tag operation specification, the NDEF data on it is stored in an NDEF-TLV object (tag 0x03, length 0x0A). 0xD1 indicates an NDEF message that consists of one record in short format with an NFC Forum record-type. The record type "T" (0x54) means it is a Text record. The Text record contains the language definition "en" (English) and the text "hey" (0x68 0x65 0x79). The data area is terminated by the Terminator-TLV (tag 0xFE, length 0x00).

Moreover there seems to be data from a previous NDEF message that was larger than the current one. As data is written in pages (4 bytes) and a tag's data area is typically not cleared when a new message is written, the old data is still readable from the tag.

You might want to read the following specifications by the NFC Forum (they are available on their website):

  • Type 2 Tag Operation Specification
  • NFC Data Exchange Format (NDEF) Technical Specification
  • NFC Record Type Definition (RTD) Technical Specification
  • NFC Text RTD Technical Specification
查看更多
登录 后发表回答