如何在Mifare Classic 1K上解释NDEF内容 [英] How to interpret NDEF content on Mifare Classic 1K
问题描述
我使用Android设备上的NFC Tools应用程序(通过内置NFC阅读器)将文本写入Mifare Classic 1K标签.这段文字是"moretto"(我的姓氏).
I write a text to a Mifare Classic 1K tag using the NFC Tools app on my Android device (through the built-in NFC reader). This text is "moretto" (my last name).
然后,我正尝试使用NFC阅读器ACR1255U和ACS提供的库来阅读此文本(NDEF格式).
Then, I'm trying to read this text (NDEF format) using the NFC reader ACR1255U with the library provided by ACS.
我能够得到以下消息:
读取块4:FF B0 00 04 10
响应:0000030ED1010A5402656E6D6F726574 9000
读取块5:FF B0 00 05 10
响应:746FFE00000000000000000000000000 9000
我知道FE
表示内容的结尾,而6D6F726574746F
是我的文字.但是,如何确定文本的开头呢?我很难理解NXP文档中描述的TLV格式.
I know that FE
indicates the end of content and 6D6F726574746F
is my text. But how do I identify where the text begins? I have difficulties to understand the TLV format described in the NXP documentation.
推荐答案
首先,在以下两个应用笔记中指定了NXP针对MIFARE Classic标签的专有NDEF映射:
First of all, NXP's proprietary NDEF mapping for MIFARE Classic tags is specified in these two application notes:
- NFC Type MIFARE Classic Tag Operation
- MIFARE Classic as NFC Type MIFARE Classic Tag
您已经发现(无法验证用作NDEF标签的MIFARE Classic标签),因此NDEF数据是存储在某些扇区(NDEF扇区,通过 MIFARE应用程序目录进行标记的数据块)的数据块中.因此,与NDEF相关的数据是这些块中所有数据的组合.
As you already found (Unable to authenticate to a MIFARE Classic tag used as NDEF tag), the NDEF data is stored in the data blocks of certain sectors (the NDEF sectors, marked as such by means of the MIFARE Application Directory). Thus, the data relevant for NDEF is the combination of all data from these blocks.
例如如果您的NDEF扇区是扇区1和2,则需要读取块4、5、6(=扇区1的块0..2)和块8、9、10(=扇区2的块0..2)汇总NDEF标签的数据.
E.g. if your NDEF sectors are sector 1 and 2, you would need to read blocks 4, 5, 6 (= blocks 0..2 of sector 1) and blocks 8, 9, 10 (= blocks 0..2 of sector 2) to aggregate the data of the NDEF tag.
在您的情况下,块4和块5中的数据似乎足够了(因为标记数据的结尾已在块5中标记,因为您正确地找到了自己).您情况下的相关标签数据是
In your case, the data from blocks 4 and 5 seems to be sufficient (since the end of tag data is marked in block 5, as you correctly found yourself). The relevant tag data in your case is
0000030E D1010A54 02656E6D 6F726574
746FFE00 00000000 00000000 00000000
标签数据本身打包为TLV(标签长度值)结构.一个TLV块由一个必需的标记字节,一个条件长度字段和一个可选的数据字段组成:
The tag data itself is packed into TLV (tag-length-value) structures. A TLV block consists of a mandatory tag byte, a conditional length field, and an optional data field:
-
没有长度和数据字段的
- TLV:
- TLVs that don't have length and data fields:
+----------+
| TAG |
| (1 byte) |
+----------+
+----------+----------+-----------+
| TAG | LENGHT n | DATA |
| (1 byte) | (1 byte) | (n bytes) |
+----------+----------+-----------+
+----------+----------+-----------+-----------+
| TAG | 0xFF | LENGHT n | DATA |
| (1 byte) | (1 byte) | (2 bytes) | (n bytes) |
+----------+----------+-----------+-----------+
在您的特定情况下有趣的标签是:
The interesting tags in your specific case are:
- NULL TLV:标记=
0x00
,没有长度字段,没有数据字段 - 终结者TLV:标记=
0xFE
,没有长度字段,没有数据字段 - NDEF消息TLV:标记=
0x03
,具有字段,具有数据字段(尽管长度可能为零)
- NULL TLV: Tag =
0x00
, no length field, no data field - Terminator TLV: Tag =
0xFE
, no length field, no data field - NDEF Message TLV: Tag =
0x03
, has field, has data field (may have zero length though)
因此,在您的情况下,数据将解码为:
Consequently, in your case the data decodes to:
00 NULL TLV (ignore, process next byte)
00 NULL TLV (ignore, process next byte)
03 NDEF Message TLV (contains your NDEF message)
0E Lenght = 14 bytes
D1010A5402656E6D6F726574746F Data = NDEF Message
FE Terminator TLV (stop processing the data)
NDEF消息可以包含0、1或多个NDEF记录.对于您而言,NDEF消息将解码为以下内容:
An NDEF message can consist of 0, 1 or more NDEF records. In your case, the NDEF message decodes to the following:
D1 Record header (of first and only record)
Bit 7 = MB = 1: first record of NDEF message
Bit 6 = ME = 1: last record of NDEF message
Bit 5 = CF = 0: last or only record of chain
Bit 4 = SR = 1: short record length field
Bit 3 = IL = 0: no ID/ID length fields
Bit 2..0 = TNF = 0x1: Type field represents an NFC Forum
well-known type name
01 Type Length = 1 byte
0A Payload length = 10 bytes
54 Type field (decoded according to the setting of TNF)
"T" (in US-ASCII) = binary form of type name urn:nfc:wkt:T
02656E6D6F726574746F Payload field (decoded according to the value of the Type field)
因此,您的NDEF消息包含一个文本记录(NFC FOrum众所周知的类型,其数据有效载荷为02656E6D6F726574746F
.此记录的有效载荷解码为:
Therefore, your NDEF message consists of one Text record (NFC FOrum well-known type with the data payload 02656E6D6F726574746F
. This record payload decodes to:
02 Status byte
Bit 7 = 0: Text is UTF-8 encoded
Bit 6 = 0: Not used
Bit 5..0 = 0x02: Length of IANA language code field
656E IANA language code field
"en" (in US-ASCII) = Text is in English
6D6F726574746F Text
"moretto" (in UTF-8)
这篇关于如何在Mifare Classic 1K上解释NDEF内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!