使用SCL010获取Mifare Ultralight的UID [英] Get UID of Mifare Ultralight with SCL010
问题描述
我想获得Mifare Ultralight NFC标签的UID。
在Java中我有这样的代码:
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();
问题是我收到两个字节而不是UID。
有什么问题? APDU是否正确?
The problem is that I receive two bytes and not the UID. What's the problem? Is the APDU correct?
推荐答案
您实际使用的命令并非您所期望的那样。
The command you are actually using is not what you might have expected.
使用此阅读器获取UID /序列号/枚举标识符的正确命令APDU是:
The correct command APDU to get the UID/serial number/enumeration identifier with this reader is:
+------+------+------+------+------+
| CLA | INS | P1 | P2 | Le |
+------+------+------+------+------+
| 0xFF | 0xCA | 0x00 | 0x00 | 0x00 |
+------+------+------+------+------+
但是,您使用的构造函数定义为:
However, the constructor you are using is defined as:
public CommandAPDU(int cla, int ins, int p1, int p2, int ne);
所以
new CommandAPDU(0xFF, 0xCA, 0x00, 0x00, 0x00)
您正在创建具有以下参数的C-APDU CLA = 0xFF
, INS = 0xCA
, P1 = 0x00
, P2 = 0x00
。到目前为止,这与上面的APDU相同。但最后一个参数是 Ne = 0x00
。 Ne = 0
表示预期响应字节数为零(而Le = 0表示预期响应字节数为(最多)256)。
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 is Ne = 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).
这样可以有效地创建以下Case-1 APDU:
This results in effectively creating the following Case-1 APDU:
+------+------+------+------+
| CLA | INS | P1 | P2 |
+------+------+------+------+
| 0xFF | 0xCA | 0x00 | 0x00 |
+------+------+------+------+
所以最多你会得到2字节状态字作为响应(表示成功 0x90 0x00
或表示状态代码错误,如 0x6X 0xXX
)。
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 like 0x6X 0xXX
).
因此您可以使用字节数组来形成APDU :
So you can either use a byte array to form your APDU:
new CommandAPDU(new byte[] { (byte)0xFF, (byte)0xCA, (byte)0x00, (byte)0x00, (byte)0x00 } )
或者你可以为<$ c $指定一个合适的值c> Ne :
new CommandAPDU(0xFF, 0xCA, 0x00, 0x00, 256)
这篇关于使用SCL010获取Mifare Ultralight的UID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!