如何在 nfcpy 库中使用 send_apdu() 命令?

How to use the send_apdu() command in nfcpy library?

我正在尝试使用 nfcpy 库中提供的 send_apdu() 命令与 android 智能手机进行交互。具体的头文件和使用过程是什么。请尽可能提供所使用功能的示例。这是函数描述的link:http://nfcpy.readthedocs.io/en/latest/modules/tag.html

没有要使用的特定头文件。 send_apdu 的大部分参数是 ISO/IEC 7816-4 APDU 语法的直接匹配:命令 Class (cla),指令代码 (ins), 参数 1 (p1), 参数 2 (p2), 命令数据 (data) 和最大响应长度 (mrl)。只有 check_status 参数没有等价物。

要构建 APDU,调用者必须提供适当的值。下面是一个使用 AID "D2760000850101"h 激活特定应用程序(NDEF 应用程序)的示例。该示例假定支持的 NFC Reader 通过 USB 连接,并且 NFC Forum Type 4 标签放置在 reader.

$ python
>>> import nfc
>>> clf = nfc.ContactlessFrontent("usb")
>>> tag = clf.connect(rdwr={'on-connect': lambda tag: False})
>>>
>>> cla = 0x00  # last or only command, no secure messaging, channel zero
>>> ins = 0xA4  # SELECT command
>>> p1 = 0x04   # Select by DF name
>>> p2 = 0x00   # First or only occurrence, Return FCI template
>>> data = bytearray.fromhex("D2760000850101")  # NDEF AID
>>>
>>> tag.send_apdu(cla, ins, p1, p2, data, check_status=False)
bytearray(b'\x90\x00')

对于这个特定的 T4T,响应数据只是两个状态字节 SW1 和 SW2,并且由于 check_status=False 可能指示也可能不指示错误(但实际上 '9000'h 表示成功)。