Write to NFC tag (ISO 14443A) fails

495 views Asked by At

I currently have the following situation:

I am trying to write a simple String to a UPM Racetrack NFC Tag. I am using Java with javax.smartcardio for this. I am using the ACR1252 writer/reader for this, and I have developed a simple java application for this.

Information about the card

  • ATR: 3B8F8001804F0CA0000003060300030000000068
  • Standard: 03 -> ISO14443A Part 3
  • Card Name: 0003 -> MIFARE ULTRALIGHT

This is my code of the util class so far:

public abstract class NFCUtils {

public static Card connect() throws Exception {
    
    TerminalFactory factory = TerminalFactory.getDefault();
    List<CardTerminal> terminals = factory.terminals().list();

    //Get the first terminal in the list
    CardTerminal terminal = terminals.get(0);
    
    System.out.println("Waiting for card....");
    terminal.waitForCardPresent(0);

    //Establish a connection
    Card card = terminal.connect("*");
    System.out.println("Card: " + card);
        
    //Get ATR
    byte[] baATR = card.getATR().getBytes();
    System.out.println("ATR: " + NFCUtils.toString(baATR));
    
    return card;
}

public static CommandAPDU createCommand(String data) {
    
    int CLA = 0xFF;
    int INS = 0xC2;
    int P1 = 0x00;
    int P2 = 0x01;
    int LE = 0x04;
    
    byte[] byteData = data.getBytes();
    
    //APDU: CLA, INS, P1, P2, Data, Offset, DataLenght
    CommandAPDU command = new CommandAPDU((byte) CLA, (byte) INS, (byte) P1, (byte) P2, byteData, 0x00, LE);
    
    return command;
}

public static ResponseAPDU writeCommandToTag(Card card, CommandAPDU command) throws CardException {
    
    CardChannel channel = card.getBasicChannel();
    ResponseAPDU commandResponse = channel.transmit(command);
    
    return commandResponse;
}

The problem is that the response always is: C003016300, which means No error information present. I am totally stuck on this, due to the lack of error information. So my question is: how can I debug this and is there maybe something obvious wrong with my command?

Any help is greatly appreciated!

0

There are 0 answers