Mifare DESFire

 

Value

 Meaning
0 Use Key 0
1 Use Key 1
2 Use Key 2
3 Use Key 3
4 Use Key 4
5 Use Key 5
6 Use Key 6
7 Use Key 7
8 Use Key 8
9 Use Key 9
A Use Key 10
B Use Key 11
C Use Key 12
D Use Key 13
E Free Access
F No Access

Service Application Structure

A DESFire Service Application

An application will contain two mandatory files, an Index File and a Free Access File and an optional number of Elementary Files containing individual data items.

Description File ID File Type
     
Index File 00 Linear Record File
Free Access File 01 Backup File
Individual Data File(s) 02 -> Max Files-1 Backup File

It must be remembered that the DESFire MF3IC40 only permits up to 16 files per application, so the maximum number of individual data files on this platform would be only 14, whereas it would be 30 on all other DESFire EV1 platforms.

The Index File

The Index file maps the tagged items within a service on to the files in which they are to be found. In most circumstances the majority (or all) of items will be located in the Free Access File, but others may reside in their own files with individual access rights.

Example Index File for CCDA Service

 

Tag (2 bytes) File ID(1 byte)
5F2B 01
DF23  01
DF32  01
DF33  01
DF56  02
DF57  03
DF6D  01
FFFF (RFU) FF (RFU)
FFFF (RFU) FF (RFU)

In the above example the majority of items are located in the Free Access File with the exception of address information accessed via tags DF56h and DF57h. Space has also been reserved in this Linear Record File to allow new entries to be added. The index file must be updated whenever data items are added to the card or deleted.

The decision on where to store data items and the access permissions associated with them is largely a scheme specific issue, although document

[4] makes recommendations about this. This file is created with the CreateLinearRecordFile command.

Cmd File No Comms Access Record Size Max Records
C1 00 00 Fx Ex* 3 As required

This file is read using the ReadRecord command and written using the WriteRecord command. When writing data CommitTransaction must be used to complete the writing and backup process. Total NV space used will be doubled due to the creation of a backup file. *Note these two bytes are sent LSB first. ‘x’ denotes a scheme specific key number.

2.3.3 The Free Access File

This file contains data in the form of a constructed BER-TLV Data Object as described in section 5 but without the final checksum. The same data structure would be represented as below on a DESFire platform.

Example of a Free Access File Contents

E0 45 50 05 00 43 4344 41DF 23 09 01 63 3710 00 0004 1301DF 32 0A 00 46 72 65 64 6572 69 63 6B DF 3308 0059 65 75 6C 6574 74 5F 2B 0502 19 39 05 16 DF 56 03 00 32 34 DF 57 09 00 50 4531 35 20 39 4C 58 FFFFFF FFFF FF FF FF FFFF FFFF FF FF FF FF FFFF FF FF FF FFFFFFFF FF FF FF FFFFFFFF FF FF FFFF FFFF FF FF FF FFFFFFFF FF FF FFFF FFFFFF FF FF FFFFFF

This data block is parsed as follows.

 

CDO

Tag

CDO

Length

Data Tag Length Format Contents Meaning
E0 45          
    50 05 00 43 43 44 41 Service Label ‘CCDA’
    DF23 09 01 63 37 10 00 04 13 01 Card No. ‘63371000041301’
    DF32 0A 00 46 72 65 64 65 72 69 63 6B Forename ‘Frederick’
    DF33 08 00 59 65 75 6C 74 74 Surname ‘Yeultt’
    5F2B 05 02 19 39 05 16 DOB ‘16/5/1939’
    DF56 03 00 32 34 House No. ‘24’
    DF57 09 00 50 45 31 35 20 39 4C 58 PostCode ‘PE15 9MX’

 

Although the Service Label (Tag 50h) must appear first in the order of data tags, the ordering of the remainder is not mandated.

Note that the CDO length value (45h underlined) is the same as the Mifare Classic example in section 5. This is because the service checksum required on the Mifare 4k platform resided in a separate primitive data object outside the CDO and did not therefore form part of its length. When creating this file the requirement for future expansion should be considered. In the above example the file size is 128 bytes of which only 71 bytes are in use. Unused space will be padded with FFh. When the file contents are changed the entire CDO must be rewritten.

Even if the original size of the Free Access File is exceeded there are two options available. The file can be deleted and recreated with the same file ID and a larger size. However, this will result in the loss of the original NV memory as there is no memory recovery on DESFire platforms. The second option is to locate some data items in individual EFs with the same permissions as the Free Access File. As long as the Index File is kept up-todate there will be no difficulty in locating these items.

This file is created using the CreateBackupDataFile command.

Cmd File No Comms Access File Size
CB 01 00 Fx Ex 80 00 00*

This file is read using the ReadData command and written with the WriteData command. When writing data CommitTransaction must be used to complete the writing and backup process. Total NV space used will be double whatever is specified when the file is created due to the existence of a backup file.

* The file size information is presented LSB first. The file size of 128 bytes is the recommended minimum. The total NV space used will be doubled due to the creation of a backup file.