I try to read NFC Mifare Ultralight cards (page 4) with an ACR1252U and the javax.smartcardio Java library this way:
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals = factory.terminals().list();
System.out.println("Terminals: " + terminals);
CardTerminal terminal = terminals.get(0);
System.out.println("Waiting for a card..");
if (terminal == null)
return;
terminal.waitForCardPresent(0);
Card card = terminal.connect("T=1");
System.out.println("Card: " + card);
System.out.println("ATR: " + bytesToHex(card.getATR().getBytes()));
System.out.println("Protocol: " + card.getProtocol());
CardChannel channel = card.getBasicChannel();
CommandAPDU command = new CommandAPDU(new byte[]{(byte) 0xFF,
(byte) 0xB0, (byte) 0x00, (byte) 0x04, (byte) 0x04});
ResponseAPDU response = channel.transmit(command);
if (response.getSW1() == 0x90) {
// success command
byte[] data = response.getData();
System.out.println(new String(data));
}
Sometimes it works and sometimes not (with the same card)
When the reading works, I get these values:
- ATR = 0x3B8F8001804F0CA0000003060300030000000068
- SW1 = 0x90
- SW2 = 0x00
And when it doesn't work, I get these:
- ATR = 0x3B80800101
- SW1 = 0x63
- SW2 = 0x00
Any idea what I'm doing wrong?