Understanding the memory structure of MIFARE Classic cards

The MIFARE Classic card is a memory storage device. The memory is divided into sectors, which are also divided into blocks of 16 bytes.

The MIFARE Classic 1K card has 16 sectors, each of which are divided into four blocks. If we do the math, we can figure out how the memory structure would be like: 16 bytes (1 block) * 4 blocks * 16 sectors = 1024 bytes.

[Figure 1. MIFARE 1K card memory structure]

The MIFARE Classic 4K card has 40 sectors, 32 of which are divided into four blocks and the remaining 8 are divided into 16 blocks. 16 bytes (1 block) * 4 blocks * 32 sectors + 16 bytes (1 block) * 16 blocks * 8 sectors = 4096 bytes. The memory structure is as follows:

[Figure 2. MIFARE 4K card memory structure]

The number on the blocks indicates its index. Each sector is protected by the site key written in the last block of the sector. For example, block 3 contains the site key for sector 1 and block 7 for sector 2. The last block in each sector also contains access conditions information such as “write”, “read” and “read & write”. The following figure demonstrates how the last block consists of:

[Figure 3. Site Key block memory structure]

Manipulating the MIFARE card layout

BioStar Client allows you to manipulate the MIFARE layout. More specifically, you can specify how many fingerprint templates you want to store in which blocks.

1. Go to Option > Mifare Card > Mifare Layout and this brings up the Mifare Layout dialog.

[Figure 4. The Mifare Layout dialog]

2. Fill out the fields on the dialog.

  • CIS Index Block: You can specify where you want to store card information in this field. It only accepts 4, 8, 12 and 16. CIS stands for Card Information Sector. The card information sector contains additional user information such as card number, user ID, user name, access group and so on. As we can guess from its name (Card Information Sector), it takes up one sector (three data blocks).
  • Number of Template: You can specify how many fingerprint / face templates you want to store. You can store up to two fingerprint templates in a MIFARE Classic 1K card. We can store templates in data blocks only. For example, if you want to store two fingerprint templates, the total number of bytes requires is 668 (334 * 2). As shown in the figure 1, templates are stored in the data blocks only. So, you need 21 blocks to store two templates, because dividing 334 by 16 equals 20.875. This means that if the starting block for Template 1 is 8, the starting block for Template 2 should be 36. Remember that we cannot store templates in the site key blocks (the last block of each sector).
  • Template Size: The default value is 334 bytes. It can vary depending on the template type.
  • Template 1-4 Start Block: You can specify the starting block for each template.

3. After specifying all the values, click Apply to Devices to transfer the settings to the devices.

4. Select the devices to which you want to transfer the settings and click OK.

5. Click Save if you want to save the settings you've configured.

6. Click Close to close the Mifare Layout dialog.

Writing templates into a MIFARE card

The procedure to write templates into a MIFARE card is different from storing card serial number in a user. The templates are not stored in a user but in a MIFARE card itself.

1. Go to the Card tab of the User page.

2. Set Card Type to Mifare Template and click Card Management.

3. The information under the Smartcard Info section is stored in the card information sector that you specified on the Mifare Layout dialog.

4. Click Write Card and place the card on the reader.

5. Click OK to close the dialog.

6. It's time to test if the templates are properly written into the card.

7. Make sure that the card reading mode is set to Use Template on Card.

8. Place the card on the reader and verify yourself using the finger you have used for the template.