在MacOS Catalina卡仿真模式下配置ACR122U

2024-05-15 23:35:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我最近从here购买了ACR122U。 我正试图将其置于卡模拟模式,使其与在启动器模式下运行PN7150的系统通信

我已设法与设备的PN532 IC(user manual)通信;发送基本命令,例如获取状态、FW版本等

但我无法将其置于卡模拟模式。下面是我尝试使用的超级简单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

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

如有任何见解,将不胜感激


Tags: databytesparammainutil模式lengthreader