Reading correct data from NFC wrist band with NXP Mifare Ultralight in C

为君一笑 提交于 2019-12-04 02:04:10

问题


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:


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


来源:https://stackoverflow.com/questions/23929387/reading-correct-data-from-nfc-wrist-band-with-nxp-mifare-ultralight-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!