[英]Error in reading and writing data on Mifare DESFire cards
I am trying to read and write data on Mifare DESFire cards using ISO 7816-4 APDU commands. 我正在尝试使用ISO 7816-4 APDU命令在Mifare DESFire卡上读取和写入数据。 I followed the steps:
我按照步骤:
{00,A4,04,00,07,D2,76,00,00,85,01,00}
. {00,A4,04,00,07,D2,76,00,00,85,01,00}
选择应用程序。 I get the response as 9100
. 9100
。 {00,A4,00,00,02,3F,00}
and I get the response as 9100
. {00,A4,00,00,02,3F,00}
选择文件,我得到9100
的响应。 {00,B0,00,00,03}
and I get an error with code 6A86
. {00,B0,00,00,03}
读取文件,我得到代码6A86
的错误。 Now I want to know the exact commands to read and write the data on the cards. 现在我想知道在卡上读取和写入数据的确切命令。 I think I still don't get the meaning of P1 and P2 in read/write commands.
我想我仍然没有在读/写命令中得到P1和P2的含义。 I already tried many other combinations but I always get errors like
6A86
, 6982
, etc. 我已经尝试过多种组合方式,但我总是得到这样的错误
6A86
, 6982
,等等。
I assume you receive the status word 9000
on success. 我假设您在成功时收到状态字
9000
。 If you actually receive 9100
when using ISO/IEC 7816-4 basic inter-industry command APDUs something very strange must be going on. 如果在使用ISO / IEC 7816-4基本的行业间命令APDU时实际收到
9100
,则必须进行一些非常奇怪的事情。 91xx
status words should only be returned when you use the ISO/IEC 7816-4 wrapped command set (ie when the class byte of the command APDU is set to 0x90). 只有在使用ISO / IEC 7816-4包装命令集时(即当命令APDU的类字节设置为0x90时),才应返回
91xx
状态字。
Let's look at what you currently do: 让我们来看看你目前做的事情:
You start my selecting the MIFARE DESFire ISO AID D2760000850100
: 您开始我选择MIFARE DESFire ISO AID
D2760000850100
:
\n00 A4 0400 07 D2760000850100This makes sure that the card is in ISO/IEC 7816-4 framing mode and automatically selects the MF (master file; ie the PICC level application).00 A4 0400 07 D2760000850100\n
You then, again(!), select the MF (PICC level application): 然后,再次(!),选择MF(PICC级应用程序):
\n00 A4 0000 02 3F00So you are now at the same level as after step 4.00 A4 0000 02 3F00\n
Finally, you try to read 3 bytes starting at offset 0 from the currently selected file using the READ BINARY APDU: 最后,您尝试使用READ BINARY APDU从当前选定的文件中读取从偏移量0开始的3个字节:
\n00 B0 0000 03Since the currently selected file is the MF you can't read binary data from it.00 B0 0000 03\n
6A86
("wrong parameter P1 and/or P2") as it tries to tell you that reading at offset 0 (P1|P2 = 0x0000) from the MF (currently selected file indicated by the upper bit of P1 being zero) makes no sense. 6A86
(“错误的参数P1和/或P2”),因为它试图告诉您从MF(当前选择的文件由高位指示)读取偏移0(P1 | P2 = 0x0000) P1为零)没有任何意义。 Therefore, before you can read binary data, you need to select an elementary file (EF), probably even located in a different application (dedicated file, DF), that contains an actual data part. 因此,在读取二进制数据之前,需要选择一个基本文件(EF),甚至可能位于包含实际数据部分的不同应用程序(专用文件DF)中。 This can be done bei either explicitly sending SELECT commands for EF (and, if necessary, the DF) or by implicitly selecting the EF using a short file identifier in P1 of the first read binary command.
这可以通过显式发送用于EF的SELECT命令(以及必要时的DF)或者通过使用第一读取二进制命令的P1中的短文件标识符来隐式地选择EF来完成。 In the latter case, you would set the upper bit of P1 to one to indicate that the remaining part of P1 encodes a short file ID.
在后一种情况下,您可以将P1的高位设置为1,以指示P1的剩余部分编码短文件ID。 In both cases you would need to know the file/application identifiers of the files and applications that you want to read from.
在这两种情况下,您都需要知道要读取的文件和应用程序的文件/应用程序标识符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.