I am creating an Android app that uses an ACS ACR1255 reader/writer to read from / write to an NFC tag.
I can read from it fine using this APDU command (which reads 16 bytes, starting at block 04h):
String APDU_COMMAND_READ_16_BYTES =
"FF" // Class: FFh
+ " B0" // Instruction: Read Binary Blocks
+ " 00" // P1: 00h
+ " 04" // P2: Block Number (the starting block)
+ " 10"; // Le: Number of bytes to read (10h = 16 bytes = 1 block)
However, I am not having much luck trying to write to the card. When I try this command:
String APDU_COMMAND_WRITE_16_BYTES =
"FF" // Class: FFh
+ " D0" // Instruction: Write Binary Blocks
+ " 00" // P1: 00h
+ " 04" // P2: Block Number (the starting block)
+ " 10" // Lc: Length of data field (10h = 16 bytes = 1 block)
+ " 01 02 03 04 05 06 07 08 01 02 03 04 05 06 07 08" // String of data units to be written
+ ""; // Le: Empty
...I get this response: 6A 81
.
According to table 12 on this page, the 6A
part means "Wrong parameter(s) P1-P2 (further qualification in SW2, see table 18)". However, table 18 says the 81
parts means "Function not supported".
So I'm not sure what's quite wrong. Could someone clarify for me what the problem is. What command do I need to successfully write to the tag?
NB - The tag in question is a MIFARE Ultralight EV1 MFOUL21. (And I can write to it fine using Android's MifareUltralight
class.)
I've just found the solution in this Standard Instructions table. That table shows that as well as the WRITE BINARY (D0
) instruction, there is also an UPDATE BINARY (D6
) instruction.
My tag already had data on the block I was trying to write to, so I need to use UPDATE BINARY instead. So just changing my D0
to D6
has solved the problem.
Update
These resources may also help other newbies to APDU: