Search code examples
nfcrfidmifareapducontactless-smartcard

Mifare 1K write block but cannot read value block


For the last three days I have been looking for block and value blocks for Mifare 1K.

For example, I wrote data successfully 1. block with this APDU:

< FF D6 00 01 10 61 79 79 69 6C 64 69 7A 66 61 74 69 68 31 31 31 
    - Start Block 01
    - Number of Bytes to Write: 16
    - Data: ayyildizfatih111
> 90 00
    - Write Binary Block Success

Then I can read as below APDU:

< FF B0 00 01 10
    - Data Read at Start Block 01
    - Number of Bytes Read: 16
> 61 79 79 69 6C 64 69 7A 66 61 74 69 68 31 31 31 90 00 
    - ASCII Mode: ayyildizfatih111
    - Read Binary Block Success

But when I tried read value block it's giving this error.

< FF B1 00 01 04 
    - ACR122U Read Value Block
> 63 00
    - Operation failed

So my question is what is the difference? When I am writing data, should I use binary blocks or value blocks. Which one is better?


Solution

  • Reading the value block fails because your block 1 is not a value block. Binary data blocks and value blocks share the same memory, the difference is just how you format the contents of the block and how you set the permissions for the block.

    In order to turn block 1 into a value block, you would set the blocks access bits to allow value block operations (decrement, transfer, restore, and (optional) increment). You would then write the block as a value block (with ACR122U V2.02: either using the Value Block Operation command or using a regular Update Binary Block command).

    The format of a value block (when using binary data block operations) is:

         +----------+----------+----------+----+----+----+----+
    Byte |   0..3   |   4..7   |   8..11  | 12 | 13 | 14 | 15 |
         +----------+----------+----------+----+----+----+----+
    Data | xxxxxxxx | yyyyyyyy | xxxxxxxx | uu | vv | uu | vv |
         +----------+----------+----------+----+----+----+----+
    

    Where xxxxxxxx is a 4 byte signed (2's complement) integer (LSB = byte 0), yyyyyyyy is the inverted value of xxxxxxxx, uu is an address byte (can be used when implementing a backup mechanism), vv is the inverted value of uu.

    If you should use binary data blocks or should use the value format depends on your application. If you want to store a 4 byte integer value and wat to use value block operations, you may prefer to use the value block format. If you want to store other data, don't need the redundancy of the value block format, only want to use binary read/write operations, you may prefer to use a block as free-form binary data block.