Android中使用NFC读取NfcA类型的芯片,Apdu指令怎么获取?

Android中使用NFC读取NfcA类型的芯片,Apdu指令怎么获取?就是 byte[] response = mNfc.transceive(cmd);中的这个cmd命令!

补充:芯片卡是NFC-A (ISO 14443-3A) TpyeA类型的,得到的Tag是android.nfc.tech.NfcA类型

大神,把解决方案放出来吧,NFCA怎么办啊,现在教程都是MifareClassic的写入

同问
NfcV的我分享一个
try {
if(nfcv.isConnected())
nfcv.close();
nfcv.connect();
byte[] command=new byte[11];
byte[] responsebyte = null;
command[0]=(byte)0x22; //标志位

command[1]=(byte)0x20; //命令位
System.arraycopy(UID, 0, command, 2, UID.length);
command[10]=(byte)0x1;
try{
responsebyte=nfcv.transceive(command);
}catch(TagLostException e){
e.printStackTrace();
}
if(responsebyte!=null){
String data=Convert.bytesToHexString(responsebyte);
Log.d("intent", "intent response="+Convert.toStringHex(data.substring(2, data.length())));
}
else
Log.d("intent", "intent response is null");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
求NfcA的 邮箱fukx2005@126.com

才了解到了,遵循NfcA标准的有很多厂商,但是可能很多的指令格式都不统一,所以网站查的资料不多。
我的问题解决了,我使用的是恩智浦(NXP)的MifareUltralight的type2的标签,读写命令官方文档描述如下:
In the examples below each command and response are written in hexadecimal format.

The top-left byte of each command and response is sent first. CRC0 and CRC1 indicate

the CRC bytes. BCC1 and Internal are reserved bytes.

For more information about command and response formatting see [MFUL].

9.1

Example of INITIALISED Formatting Procedure

This example shows how the INITIALISED Formatting Procedure (see

section 6.5.1

The example of INITIALISED Formatting Procedure is described below

) may

be implemented for a MIFARE Ultralight tag.

READ command with page address = 02h to check if the lock bits are equal to 0h,

and the CC-OTP is set to byte 0 = E1h, byte1 =10h, byte 2 bigger than or equal to

06h, and byte 3 equal to 00h.

a.

Command: 30 02 CRC0 CRC1

b.

Expected Response: BCC1 Internal 00 00 E1 10 06 00 00 00 00 00 00 00 00 00

CRC0 CRC1

WRITE command with page address = 03h to set the CC to byte 0 = E1h, byte 1 =

10h, byte 2 = 06h, byte 3 = 00h.

a.

Command: A2 03 E1 10 06 00 CRC0 CRC1

b.

Expected Response: Ah (acknowledge 4 bits)

WRITE command with page address = 04h to write an empty NDEF Message TLV

and the Terminator TLV.

a.

Command: A2 04 03 00 FE 00 CRC0 CRC1

b.

Expected Response: Ah (acknowledge 4 bits)

9.2

Example of Writing an NDEF Message setting the tag in Ultralight

BLOCKED READ/WRITE

This example shows how to set a MIFARE Ultralight tag from the INITIALISED state to

the Ultralight BLOCKED READ/WRITE state. It is a combination of:

Transition from INITIALISED to READ/WRITE (see [NFCT2T]),

transition from READ/WRITE to Ultralight READ/WRITE (see

section 6.4.2

transition from Ultralight READ/WRITE to Ultralight BLOCKED READ/WRITE (see

), and

section 6.4.3

The NDEF Message TLV occupies 2 pages (page 04h and 05h). The page 05h is filled

with NULL TLVs to have only the NDEF Message TLV in page 04h and 05h. In this way

the Terminator TLV is located on byte 0 of page 06h. The lock bytes are set to have

read-only access to the NDEF Message TLV (i.e. Page 04h, and 5h), but not to the rest

of the data area i.e. from page 06h where the Terminator TLV is stored. Moreover the

lock bytes have the block-locking bits set to 1b to fix the access configuration of the tag.

).

As precondition the MIFARE Ultralight tag is in INITILIAZED state. The NDEF message

inside the NDEF Message TLV is an empty NDEF message (see

APPENDIX A

The example is described below:

of

[NFCT2T]).

NXP Semiconductors

AN1303

MIFARE Ultralight as Type 2 Tag

AN1303

All information provided in this document is subject to legal disclaimers.

© NXP B.V. 2012. All rights reserved.

Application note

COMPANY PUBLIC

Rev. 1.5 — 2 October 2012

130315

48 of 51

WRITE command with page address 04h to set byte 0 = 03h, byte 1 = 03h, byte 2 =

D0h, byte 3 = 00h to write the first part of the NDEF Message TLV.

a.

Command: A2 04 03 03 D0 00 CRC0 CRC1

b.

Expected Response: Ah (acknowledge 4 bits)

WRITE command with page address 05h to set byte 0 = 00h, byte 1 = 00h, byte 2 =

00h, byte 3 = 00h to write the second part of the NDEF Message TLV, and three

NULL TLVs.

a.

Command: A2 05 00 00 00 00 CRC0 CRC1

b.

Expected Response: Ah (acknowledge 4 bits)

WRITE command with page address 06h to set byte 0 = EFh, byte 1 = 00h, byte 2 =

00h, byte 3 = 00h to write the Terminator TLV.

a.

Command: A2 05 EF 00 00 00 CRC0 CRC1

b.

Expected Response: Ah (acknowledge 4 bits)

WRITE command with page address 02h to set byte 0 = 00h, byte 1 = 00h, byte 2 =

3Fh, byte 3 = 00h to write the lock bytes equal to 3F00h to lock page 04h, page 05,

and the access configuration of the tag.

a.

Command: A2 05 00 00 3F 00 CRC0 CRC1

b.

Expected Response: Ah (acknowledge 4 bits)

cmd=new byte[]{0x60,0x08,0xff,0xff,0xff,0xff,0xff,0xff};//卡请求
//TypeA 类型的第一个数据是0x60,我要想读的扇区是第2扇区的第0块,
//也就是第8块的数据,KeyA密码是六个字节的0xff,0xff,0xff,0xff,0xff,0xff
str+="Card Number:"+nfcaTag.transceive(cmd);
这种方式 小米5 可以读取数据, 但换啦lenovo p1 用这种方式 报异常 android.nfc.TagLostException: Tag was lost.