I want get the UID of the Mifare Ultralight NFC tag. In Java I have this code:
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals = factory.terminals().list();
System.out.println("Terminals: " + terminals);
CardTerminal terminal = terminals.get(0);
Card card = terminal.connect("*");
System.out.println("card: " + card);
CardChannel channel = card.getBasicChannel();
ResponseAPDU answer = channel.transmit(new CommandAPDU(0xFF, 0xCA, 0x00, 0x00, 0x00));
byte[] uid = answer.getBytes();
The problem is that I receive two bytes and not the UID. What's the problem? Is the APDU correct?
After read this code For read and write purpose use bellow commands.
And Read From page : 04 to page : 07 Command is:
Write into Page 04:
The command you are actually using is not what you might have expected.
The correct command APDU to get the UID/serial number/enumeration identifier with this reader is:
However, the constructor you are using is defined as:
So with
you are creating a C-APDU with the following parameters
CLA = 0xFF
,INS = 0xCA
,P1 = 0x00
,P2 = 0x00
. So far this is the same as the above APDU. But the last parameter isNe = 0x00
.Ne = 0
means that the number of expected response bytes is zero (whereas Le = 0 would mean that the number of expected response bytes is (up to) 256).This results in effectively creating the following Case-1 APDU:
So at most you will get the 2-byte status word as a response (either indicating success with
0x90 0x00
or indicating an error with a status code like0x6X 0xXX
).So you can either use a byte array to form your APDU:
Or you can specify a proper value for
Ne
: