1
votes

How can I get the available memory of a MIFARE DESFire EV1 card? I know some Android applications show the available memory. So is there any APDU command to get the available memory?

1

1 Answers

3
votes

You can get the total memory size using the GetVersion command:

<-- 90 60 0000 00
--> ZZ YY XX WW VV TT SS 91AF
<-- 90 AF 0000 00
--> ZZ YY XX WW VV TT SS 91AF
<-- 90 AF 0000 00
--> UUUUUUUUUUUUUU NNNNNNNNNN WW YY 9100

Where SS is the storage size and can be decoded as

int storageBytes = 1 << ((int)SS & 0x0FE) >>> 1);
bool storageExact = ((int)SS & 0x01) != 0;

The lowest bit indicates if the indicated storage size (in bytes) is an exact value or if the actual storage size is between storageBytes and storageBytes * 2.

You can also get the available free memory (in bytes) using the FreeMem command:

<-- 90 6E 0000 00
--> SSSSSS 9100