使用NXP Mifare Ultralight in C从NFC腕带读取正确的数据 [英] Reading correct data from NFC wrist band with NXP Mifare Ultralight in C

查看:239
本文介绍了使用NXP Mifare Ultralight in C从NFC腕带读取正确的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对NFC设备阅读非常陌生,但是我设法使用

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).

我不明白的是,当我从MIFARE Ultralight波段读取数据时,会遇到很多垃圾.

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

例如,我在标签中有数字255555574558888(我使用Android设备将此数字写入标签中).

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

现在,当我跑步时:

nfc-mfultralight r /home/user/dump

我明白了

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

这是来自libnfc的示例,因此该程序不应该只读取正确的数据吗?我正在使用的Android应用只会看到值255555574558888.值-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?

我正在使用ACR122从标签中读取数据.

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

PS:这是我的第一个使用NFC设备,libnfc和MIFARE Ultralight标签的项目,因此,您认为我应该阅读的所有内容都请告诉我.

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.

编辑1

所以我发现了以下问题:读取NFC Mifare带有恩智浦阅读器库的卡

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

我看到3d之后是0a,然后是d1,但是3d之前的所有值是什么?这是因为libnfc吗?

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?

推荐答案

您在页面0和1(字节0至7)中使用的数据是卡的UID.第2页包含特定于卡的数据(字节8和9)和锁定字节(字节10和11).第3页包含功能容器(CC),该功能容器指示该标签是根据NFC论坛2类标签操作规范版本1.1进行格式化的.标签的用户数据区域从第4页开始.

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.

由于此标签遵循NFC论坛的标签操作规范,因此其上的NDEF数据存储在NDEF-TLV对象(标签0x03,长度0x0A)中. 0xD1表示NDEF消息,该消息由一个具有NFC论坛记录类型的短格式记录组成.记录类型"T"(0x54)表示它是文本记录.文本记录包含语言定义"en"(英语)和文本"hey"(0x68 0x65 0x79).数据区域由Terminator-TLV终止(标签0xFE,长度为0x00).

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).

此外,似乎前一个NDEF消息中的数据大于当前的数据.由于数据是以页(4字节)的形式写入的,并且在写入新消息时通常不会清除标签的数据区域,因此仍然可以从标签读取旧数据.

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.

您可能想通过 NFC论坛阅读以下规范(可在其网站上找到) ):

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

  • 类型2标签操作规范
  • NFC数据交换格式(NDEF)技术规范
  • NFC记录类型定义(RTD)技术规范
  • NFC文本RTD技术规范

这篇关于使用NXP Mifare Ultralight in C从NFC腕带读取正确的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆