首先,恩智浦的MIFARE经典标签专有NDEF映射在这两个应用笔记指定:
正如你已经发现(Unable to authenticate to a MIFARE Classic tag used as NDEF tag)时, NDEF数据存储在某些扇区(NDEF扇区,通过MIFARE Application Directory标记)的数据块中。因此,与NDEF相关的数据是来自这些块的所有数据的组合。
E.g.如果您的NDEF扇区是扇区1和扇区2,则需要读取扇区4,5,6(=扇区1的扇区0..2)和扇区8,9,10(扇区2的扇区0..2)来聚合NDEF标签的数据。
对于您的情况,块4和块5的数据似乎已经足够了(因为标签数据的结束标记在块5中,因为您正确地发现了自己)。您的案例中的相关标签数据为
0000030E D1010A54 02656E6D 6F726574
746FFE00 00000000 00000000 00000000
标签数据本身被打包到TLV(标签长度值)结构中。甲TLV块由一个强制标记字节,条件长度字段,和一个可选的数据字段的:
- 的TLV不具有长度和数据字段:
+----------+
| TAG |
| (1 byte) |
+----------+
- 的TLV,其中数据场具有从0到254字节的长度:
+----------+----------+-----------+
| TAG | LENGHT n | DATA |
| (1 byte) | (1 byte) | (n bytes) |
+----------+----------+-----------+
- 的TLV,其中数据字段具有从255到65534字节的长度:
+----------+----------+-----------+-----------+
| TAG | 0xFF | LENGHT n | DATA |
| (1 byte) | (1 byte) | (2 bytes) | (n bytes) |
+----------+----------+-----------+-----------+
在特定情况下,有趣的标签是:
- NULL TLV:标签=
0x00
,没有长度字段,没有数据字段
- 终结者TLV:标签=
0xFE
,没有长度字段,没有数据字段
- NDEF消息的TLV:标签=
0x03
,具有字段,具有数据字段(可以具有零长度虽然)
因此,在您的情况下,数据解码为:
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消息进行解码,以执行以下操作:
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论坛公知的类型与数据有效载荷02656E6D6F726574746F
的该记录的有效载荷进行解码,以:
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)