Defining a NDEF Message

前提是你 提交于 2019-12-02 13:52:18

问题


I am working on a Python project with my Raspberry Pi and the RFID-RC522 board. As NFC tags I use NXP NTAG213. My plan now is to store links on the tags. I can read/write on them without a problem. But I don't understand how to define the NDEF header for the stored data on the tags.

When I write a link on the tags with my smartphone and read it with my program the stored data on the tag looks like this:

The NDEF header for the URL "http://www.gmx.at" is

[3, 11, 209, 1, 7, 85, 1, ... (Data)]

I recognized that some of these parameters change when I write another link, but some still stay the same.

I found this tutorial which describes the different fields of the NDEF header but I still don't get how I need to set them to store a link to a website.

I would be very happy if someone can describe how I need to calculate/define the parameters for a link correctly.


回答1:


In order to understand the NDEF format and the way how NDEF formatted data is stored on an NFC Forum Type 2 tag (which is the tag platform that is implemented by the NTAG213), I suggest that you read the following NFC Forum specifications:

  • Type 2 Tag Operation Specification
  • NFC Data Exchange Format (NDEF)
  • URI Record Type Definition

The data that you read from the tag is an NDEF Message TLV object containing an NDEF message that consists of one URI record.

  • NDEF Message TLV:

    0x03             TLV tag = NDEF Message TLV
      0x0B           TLV length = 11 bytes
      0xD1 ... 0x74  TLV value = NDEF message
    

    This means that the tag contains an NDEF message with a length of 11 bytes. The NDEF message is 0xD1 ... 0x74.

  • NDEF Message:

    0xD1             Record header
                       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
      0x01           Type length = 1 byte
      0x07           Payload length = 7 bytes
      0x55           Type field = "U" (in US-ASCII) = binary form of type name urn:nfc:wkt:U
      0x01 ... 0x74  Payload field = URI record payload
    

    This means that the NDEF message consists of one URI record (type name urn:nfc:wkt:U) following the URI Record Type Definition.

  • URI record payload:

    0x01             Identifier byte = URI prefix "http://www."
    0x67 ... 0x74    URI field (UTF-8 encoded) = "gmx.at"
    

    This means that the URI record points to the URI "http://www.gmx.at".



来源:https://stackoverflow.com/questions/35363563/defining-a-ndef-message

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