Yan Naing Win
Yan Naing Win

Reputation: 3

SELECT APDU command on Raspberry Pi pico with PN532 repond nothing

I have Raspberry Pi pico with PN532 NFC/RFID breakout board.
connecting SPI interface and using circuitPython with Thonny IDE.
When I read UID from iso7816 smart card and it worked.
But sending SELECT APDU command to card respond nothing.
I am using this PN532 library https://github.com/adafruit/Adafruit_CircuitPython_PN532

Here is the Thonny Shell reponse -

Found PN532 with firmware version: 1.6<br>
Waiting for RFID/NFC card to write to!<br>
.....<br>
Found card with UID: ['0x4', '0x28', '0x2c', '0x42', '0x5e', '0x69', '0x80']<br>
Authenticating block 4 ...<br>
[0, 164, 4, 0, 7, 160, 0, 0, 16, 0, 1, 18]<br>
bytearray(b'%')

This is my codes

import board
import busio
from digitalio import DigitalInOut, Direction, Pull

# Additional import needed for I2C/SPI
# from digitalio import DigitalInOut
#
# NOTE: pick the import that matches the interface being used
#
# from adafruit_pn532.i2c import PN532_I2C

from adafruit_pn532.spi import PN532_SPI
from adafruit_pn532.adafruit_pn532 import COMMAND_TGGETDATA
from adafruit_pn532.adafruit_pn532 import COMMAND_TGSETDATA


# SPI connection:
spi = busio.SPI(board.GP2, board.GP3, board.GP4)
cs_pin = DigitalInOut(board.GP5)
pn532 = PN532_SPI(spi, cs_pin, debug=False)

def printString(data1):
    out = ''
    for x in range(len(data1)):
        out += '%02x' % data1[x]
    return out

ic, ver, rev, support = pn532.firmware_version
print("Found PN532 with firmware version: {0}.{1}".format(ver, rev))

# Configure PN532 to communicate with MiFare cards
pn532.SAM_configuration()

print("Waiting for RFID/NFC card to write to!")

key = b"\xFF\xFF\xFF\xFF\xFF\xFF"

while True:
    # Check if a card is available to read
    uid = pn532.read_passive_target(timeout=0.5)
    print(".", end="")
    # Try again if no card is available.
    if uid is not None:
        break

print("")

print("Found card with UID:", [hex(i) for i in uid])
print("Authenticating block 4 ...")

def sendAPDU(apdu):
    sendData = pn532.call_function(COMMAND_TGSETDATA,params=apdu)

def getAPDU():
    result = pn532.call_function(COMMAND_TGGETDATA,255)
    print(result)
    apdu = printString(result)[2:]
    return apdu

cardApdu = [0x00, 0xA4, 0x04, 0x00, 0x07, 0xA0, 0x00, 0x00, 0x10, 0x00, 0x01, 0x12] # select apdu command AID "0xA0000010000112"
print(cardApdu)
pos = sendAPDU(cardApdu)
answerPos = getAPDU()
print(answerPos)

Upvotes: 0

Views: 1397

Answers (1)

mig tam
mig tam

Reputation: 1

hey your command is correct is was just missing the LE at the end

cardApdu = [0x00, 0xA4, 0x04, 0x00, 0x07, 0xA0, 0x00, 0x00, 0x10, 0x00, 0x01, 0x12]

the command should be something like this.

[0x00, 0xA4, 0x04, 0x00, 0x07, 0xA0, 0x00, 0x00, 0x10, 0x00, 0x01, 0x12, 0x00]

Upvotes: 0

Related Questions