Anviori
Anviori

Reputation: 15

Configuring the ACR122U in Card Emulation Mode - MacOS Catalina

I recently purchased the ACR122U from here. I am attempting to place it into Card Emulation mode to have it communicate with a system running a PN7150 in Initiator Mode.

I've managed to communicate with the device's PN532 IC (user manual); sending basic commands, e.g. getting the status, FW version, etc...

I am unable to place it in card emulation mode though. Below is the super simple python script I'm using to attempt to do this:

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()

This results in the error:

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

I'm assuming this means that no response was received and I don't think it's a driver issue because other commands work just fine.

Any insight will be greatly appreciated.

Upvotes: 0

Views: 995

Answers (0)

Related Questions