使用 Desfire EV1 标签和 nfcpy 的问题
Problems working with Desfire EV1 tags and nfcpy
尝试将 ndef 记录写入 Desfire EV1 标签无效。我相信这是因为标签没有格式化,但是,当我尝试这样做时(使用 tagtool.py)我得到一个错误。
我正在使用通过迷你 UART 连接到 Raspberry Pi 3 B+ 的 Adafruit PN532(S0 而不是 AMA0,因为我需要蓝牙用于其他用途)。
python tagtool.py --device tty:S0 format
No handlers could be found for logger "nfc.llcp.sec"
[nfc.clf] searching for reader on path tty:S0
[nfc.clf] using PN532v1.6 at /dev/ttyS0
** waiting for a tag **
[nfc.tag.tt4] no ndef capability file
[nfc.tag.tt4] format error: no ndef or not writeable
Sorry, I could not format this tag.
python tagtool.py --device tty:S0 -v
No handlers could be found for logger "nfc.llcp.sec"
[nfc.clf] searching for reader on path tty:S0
[nfc.clf] using PN532v1.6 at /dev/ttyS0
** waiting for a tag **
Type4ATag MIU=63 FWT=0.077329
[nfc.tag.tt4] no ndef capability file
Memory Dump:
[nfc.tag.tt4] no ndef capability file
Python 2.7.13 (default, Sep 26 2018, 18:42:22)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import nfc
No handlers could be found for logger "nfc.llcp.sec"
>>> clf = nfc.ContactlessFrontend('tty:S0')
>>> tag = clf.connect(rdwr={'on-connect': lambda tag: False})
>>> print(tag)
Type4ATag MIU=63 FWT=0.077329
>>> print(tag.ndef)
None
查看 tagtool 源代码后,似乎只添加了对格式化类型 1 和 3 标签的支持。
def format_tt1_tag(self, tag):
if self.options.magic is not None:
tag.write_byte(8, self.options.magic)
if self.options.ver is not None:
tag.write_byte(9, self.options.ver)
if self.options.tms is not None:
tag.write_byte(10, self.options.tms)
if self.options.rwa is not None:
tag.write_byte(11, self.options.rwa)
def format_tt2_tag(self, tag):
pass
def format_tt3_tag(self, tag):
attribute_data = tag.read_from_ndef_service(0)
if self.options.ver is not None:
attribute_data[0] = self.options.ver
if self.options.nbr is not None:
attribute_data[1] = self.options.nbr
if self.options.nbw is not None:
attribute_data[2] = self.options.nbw
if self.options.max is not None:
attribute_data[3:5] = struct.pack(">H", self.options.max)
if self.options.rfu is not None:
attribute_data[5:9] = 4 * [self.options.rfu]
if self.options.wf is not None:
attribute_data[9] = self.options.wf
if self.options.rw is not None:
attribute_data[10] = self.options.rw
if self.options.len is not None:
attribute_data[11:14] = struct.pack(">I", self.options.len)[1:]
if self.options.crc is not None:
attribute_data[14:16] = struct.pack(">H", self.options.crc)
else:
checksum = sum(attribute_data[:14])
attribute_data[14:16] = struct.pack(">H", checksum)
tag.write_to_ndef_service(attribute_data, 0)
def format_tt4_tag(self, tag):
pass
tagtool.py
脚本可以格式化任何 NFC 论坛类型 1/2/3/4 标签。这些标签配备了由 NFC 论坛标签规范定义的 NDEF 管理信息。 Mifare Desfire EV1 是一个具有应用标识符 (AID) 和相关文件的 multi-application 标签。对于 NDEF 存储,特定的 AID 必须具有定义的文件结构。这通常使用制造商工具完成。
尝试将 ndef 记录写入 Desfire EV1 标签无效。我相信这是因为标签没有格式化,但是,当我尝试这样做时(使用 tagtool.py)我得到一个错误。
我正在使用通过迷你 UART 连接到 Raspberry Pi 3 B+ 的 Adafruit PN532(S0 而不是 AMA0,因为我需要蓝牙用于其他用途)。
python tagtool.py --device tty:S0 format
No handlers could be found for logger "nfc.llcp.sec"
[nfc.clf] searching for reader on path tty:S0
[nfc.clf] using PN532v1.6 at /dev/ttyS0
** waiting for a tag **
[nfc.tag.tt4] no ndef capability file
[nfc.tag.tt4] format error: no ndef or not writeable
Sorry, I could not format this tag.
python tagtool.py --device tty:S0 -v
No handlers could be found for logger "nfc.llcp.sec"
[nfc.clf] searching for reader on path tty:S0
[nfc.clf] using PN532v1.6 at /dev/ttyS0
** waiting for a tag **
Type4ATag MIU=63 FWT=0.077329
[nfc.tag.tt4] no ndef capability file
Memory Dump:
[nfc.tag.tt4] no ndef capability file
Python 2.7.13 (default, Sep 26 2018, 18:42:22)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import nfc
No handlers could be found for logger "nfc.llcp.sec"
>>> clf = nfc.ContactlessFrontend('tty:S0')
>>> tag = clf.connect(rdwr={'on-connect': lambda tag: False})
>>> print(tag)
Type4ATag MIU=63 FWT=0.077329
>>> print(tag.ndef)
None
查看 tagtool 源代码后,似乎只添加了对格式化类型 1 和 3 标签的支持。
def format_tt1_tag(self, tag):
if self.options.magic is not None:
tag.write_byte(8, self.options.magic)
if self.options.ver is not None:
tag.write_byte(9, self.options.ver)
if self.options.tms is not None:
tag.write_byte(10, self.options.tms)
if self.options.rwa is not None:
tag.write_byte(11, self.options.rwa)
def format_tt2_tag(self, tag):
pass
def format_tt3_tag(self, tag):
attribute_data = tag.read_from_ndef_service(0)
if self.options.ver is not None:
attribute_data[0] = self.options.ver
if self.options.nbr is not None:
attribute_data[1] = self.options.nbr
if self.options.nbw is not None:
attribute_data[2] = self.options.nbw
if self.options.max is not None:
attribute_data[3:5] = struct.pack(">H", self.options.max)
if self.options.rfu is not None:
attribute_data[5:9] = 4 * [self.options.rfu]
if self.options.wf is not None:
attribute_data[9] = self.options.wf
if self.options.rw is not None:
attribute_data[10] = self.options.rw
if self.options.len is not None:
attribute_data[11:14] = struct.pack(">I", self.options.len)[1:]
if self.options.crc is not None:
attribute_data[14:16] = struct.pack(">H", self.options.crc)
else:
checksum = sum(attribute_data[:14])
attribute_data[14:16] = struct.pack(">H", checksum)
tag.write_to_ndef_service(attribute_data, 0)
def format_tt4_tag(self, tag):
pass
tagtool.py
脚本可以格式化任何 NFC 论坛类型 1/2/3/4 标签。这些标签配备了由 NFC 论坛标签规范定义的 NDEF 管理信息。 Mifare Desfire EV1 是一个具有应用标识符 (AID) 和相关文件的 multi-application 标签。对于 NDEF 存储,特定的 AID 必须具有定义的文件结构。这通常使用制造商工具完成。