0

我最近从这里购买了 ACR122U 。我正在尝试将其置于卡仿真模式以使其与在启动器模式下运行 PN7150 的系统进行通信。

我已经设法与设备的 PN532 IC(用户手册)进行通信;发送基本命令,例如获取状态、固件版本等...

不过,我无法将其置于卡模拟模式。下面是我用来尝试执行此操作的超级简单的 python 脚本:

from smartcard.System import *
from smartcard import util

'''
Command Application Protocol Data Units

C-APDU Structure:
    [ Class + Instruction + Param_1 + Param_2 + Data Length + Data ]
'''

# ACS Direct Transmit Header - [ Class + Instruction + Param_1 + Param_2 ] #
ACS_DIRECT_TRANSMIT = [ 0xFF, 0x00, 0x00, 0x00 ]

# PN532 COMMANDS - [ Data Length + Data ] #
PN532_CMDS = {
                'GET_READER_FW_VERSION' : [ 0x02, 0xD4, 0x02 ],
                'GET_READER_STATUS'     : [ 0x02, 0xD4, 0x04 ],

                # Enable ISO/IEC 14443-4 PICC emulation & automatic RATS #
                'SET_PARAMETERS'        : [ 0x03, 0xD4, 0x12, 0x30 ],
                'CONFIGURE_CE_MODE'     : [
                                            0x27,             # Data Length
                                            0xD4, 0x8C,       # Command header
                                            0x05,             # Mode - PICC/Passive
                                            0x04, 0x00,       # ATQA
                                            0x12, 0x34, 0x56, # UID: Last 3 bytes
                                            0x20,             # SAK

                                            # =====[ Unused ] ===== #
                                            # FeliCa Params #
                                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                            0x00, 0x00,

                                            # ATR Bytes #
                                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                            # ===== [ Unused ] ===== #

                                            0x00, # General Bytes Length.
                                            0x00  # Historical Bytes Length.
                                          ]
             }

def printResponseApdu(data, sw1, sw2):
    data = util.toHexString(data)
    status = util.toHexString([sw1, sw2])
    print(f"R-APDU << Data:{data} Status:{status}")

def main():
    scReaders = readers()
    print("Available readers:", scReaders)

    reader = scReaders[0]
    print("Using:", reader)
    connection = reader.createConnection()

    connection.connect()
    print("Connection Established!")

    respData, sw1, sw2 = connection.transmit(ACS_DIRECT_TRANSMIT + PN532_CMDS['CONFIGURE_CE_MODE'])
    printResponseApdu(respData, sw1, sw2)

if __name__ == "__main__":
    main()

这会导致错误:

 ...
        sw1 = (response[-2] + 256) % 256
    IndexError: list index out of range

我假设这意味着没有收到响应,我认为这不是驱动程序问题,因为其他命令工作正常。

任何见解将不胜感激。

4

0 回答 0