How to write and read data blocks

Forum / MIFARE and NFC Reader IC`s / How to write and read data blocks

  • 9. January 2018 at 1:09
    I'm having difficult to write and read data blocks. The problem is to understand the correct sequence of the instructions.
    I managed how to read the ID of the MIFARE Classic 1kB. It's working fine. I'd like to know if anyone can help me saying what I'm doing wrong. The sequence that I'm using is:

    1. After read the tag ID it's build a array of 12 bytes to send, where:
    Byte 0: 0x60 (Key A)
    Byte 1: 0x05 (Block Address)
    Byte 2 to Byte 7: 0xFF (password)
    Byte 8 to Byte 11: Tag ID

    2. Send the array writing 0x0E (Authentication) in the 0x01 (Command register).

    3. Read the register 0x08 (Status2reg) to know if the Reader in the Encrypted mode (bit MFCrypto1On).

    So, when I read the Status2reg I got the value "wait for data".

    I'd like to know if is the rigth sequence or I'm missing something? For instance, CRC...
    + 0  |  - 0

    Re: How to write and read data blocks

    9. January 2018 at 10:59
    Hi Danilo,

    The MIFARE Classic has usually one byte commands and reading and writing data blocks contains all 16 bytes of a block.

    What you published in your post is obviously required for your reader/driver infrastructure. Usually the reader manufacturer define the APDU sequences you have to use for communication. The MIFARE Classic uses an own protocol and the encryption is usually handled in the NFC reader frontend IC. All reader interface I know allow to save a key with a separate command inside of the reader and refer to it for all following commands.

    The TapLinx team

    + 0  |  - 0

    Re: How to write and read data blocks

    12. February 2018 at 10:29
    Hi,

    I am trying to develop an app that store value into the card. I am using VB6 Sample Code supplied by the ACS reader.

    I write a value (number) into Sector 3 Block 3. The write is not succesfull , there is error
    "Unknown Reader Error : 3040"
    . After that, i can not login into the Sector 3 anymore. There is error
    "Operation Failed : -3030"
    .

    Why this is happening ?
    Which Sector is safe / recommended to write, which is not ?

    + 0  |  - 0

    Re: How to write and read data blocks

    12. February 2018 at 12:37
    Hi Yocki,

    This error message depends on your reader library. Please try to get the user manual from the reader manufacturer.

    Please take in mind, for the MIFARE Classic you have to authenticate to each sector before you can access a block in this sector.

    Regards,
    The TapLinx team

    + 1  |  - 0

    Re: How to write and read data blocks

    12. February 2018 at 23:20
    The error messages are only that. There are no additional clues what cause the error.
    I am using mifare 1K and ACR Reader by ACS. i also have supplied the authentication required (using KeyA). I am able to write to another block (Sector 2 Block 1) and succesfully read what i have been written.
    But, when i write to Sector 3 Block 3, it fails. Moreover, the Sector cant be accessed again. I tried with 10 cards and all give the same result.
    Whats wrong with Sector 3 ?
    + 0  |  - 0

    Re: How to write and read data blocks

    13. February 2018 at 9:43
    Hi Yocki,

    OK, we can exclude a reader issue. Sector 3 behaves like all other sectors. The only difference is sector 0 where the first block is not writable and contains the UID. All other sectors have an identical access behavior.

    You are sure the MIFARE Classic is a genuine NXP product? It exist manufacturers who sell counterfeit cards which behaves a little bit like bit like a NXP product, but not at all. Those products have a lot of technical problems and will at the end not satisfy for requirements. You should check this question with your local card dealer.

    The TapLinx team

    + 0  |  - 0

    Re: How to write and read data blocks

    16. March 2018 at 21:18
    Hy everyone.
    Thanks for all answers.
    Now I manage how to communicate with Tags and write and read data blocks. I'm working with Microchip Microcontroller in C.
    If somenone needs some information I can help.

    Thank you.
    + 0  |  - 0

    Re: How to write and read data blocks

    27. February 2019 at 14:13
    I am making an Application for MiFare Classic 1K. I need to write data on all sectors, i can write and read data from all blocks easily, but
    When I am writing Block 3 and try to read data by using new key that i have written in block 3 then it is showing blank data. Before writing block 3(before change default facory key) I can read all data but I am getting blank when I change block 3(Default Factory key). Please guide me...
    Thanks in advance
    + 0  |  - 0

    Re: How to write and read data blocks

    28. February 2019 at 13:03
    Hi Deepak,

    Block 3 is the sector trailer and contains the keys A and B and the access permission bits. You should be careful writing this block. It exists access condition bits which makes the sector inaccessible!

    Please have a look to the picture below:



    Bytes 0…5 contains key A and bytes 10…15 key B. Bytes 6…8 contain the access condition. If you write to block 3, always read the block first and mask out and insert the bytes you want to change. Before you can read any block of any sector you must authenticate to this sector before.

    Block 0 of sector 0 cannot be written, because it contains manufacturer data and is read-only.

    The TapLinx team
    Attachments:
    You must be logged in to view attached files.

    + 1  |  - 0

    Re: How to write and read data blocks

    28. February 2019 at 15:28
    Hiiiii Thanks for this useful answer,
    Can you explain or give me any link for implementation it in Android?
    + 0  |  - 0

    Re: How to write and read data blocks

    6. March 2019 at 13:41
    Hi Deepak,

    for Android I recommend using TapLinx, a SDK for making the programming for Android easier. The TapLinx library allows you to use API functions like createApplication(), createFile(), readDate() etc. The benefit is that you do not need any datasheets and you also do not need to deal with encryption separately. It is handled inside of TapLinx.

    Find more information here:

    https://www.mifare.net/en/products/tools/taplinx/

    Kind regards,
    The TapLinx team
    + 0  |  - 0

    Re: How to write and read data blocks

    14. March 2019 at 14:22
    I have checked Sample given by TapLinx, but I have same problem.
    I wrote "deepaktiwarideep" in sector 4 block 0, and also wrote the same on sector 4 block 3 (Sector Trailer). But when I authenticate this sector with "deepak" KEY A then it will authenticate it successfully, but when i read sector 4 block 0 then i didn't get "deepaktiwarideep", I only got byte array with single value i.e. "4"(byte[] {4}).
    + 0  |  - 0

    Re: How to write and read data blocks

    15. March 2019 at 11:08
    Hi Deepak,

    Please take in mind: the sector trailer contains also the access condition bytes (see picture above). Please take also in mind: it exists combinations which makes a sector inaccessible!

    I would always read the block and overwrite the key bytes and write the block back until you really know what you do.

    The TapLinx team

    + 1  |  - 0

    Re: How to write and read data blocks

    18. March 2019 at 14:54
    Thanks,

    Now this is working fine. I am changing only Key A so now its working.

    Thanks a lot
    + 0  |  - 0

    Re: How to write and read data blocks

    15. July 2020 at 4:47
    Hello I wan to input this in my Mifare card SECTOR 0 BLOCK 1
    how do I do it?
    what program will I have to use?


    Thanks
    Attachments:
    You must be logged in to view attached files.

    + 0  |  - 0
Viewing 15 posts - 1 through 15 (of 21 total)

You must be logged in to reply to this topic.