How to Read MIFARE DESFire Cards
← Back to the smart card SDK and developer centre
How do you read a MIFARE DESFire card? Put it on a contactless PC/SC reader such as the ACR1252U, ACR1552U or ACR122U and send the card's own native DESFire commands, wrapped in ISO 7816-4 APDUs with class byte 90. The reader passes them to the card unchanged. The read sequence is always the same: GetVersion to confirm the card is a DESFire, GetApplicationIDs to list the applications, SelectApplication to open one, GetFileIDs and GetFileSettings to see its files and their access rights, then ReadData on a file. Replies end in 91 00 for success, 91 AF for "more data follows" and 91 AE when the step needs a key you have not authenticated with.
A DESFire card is not a memory you can simply read, like a MIFARE Classic sector. It holds applications, each with its own files and keys, and every file has its own access rights. Without a key you can read the card version, and usually the list of applications and any file whose read access is set to free. Everything else needs authentication with the right key, which is your application's job, not the reader's. This page shows the sequence in the ACS tools first and then in a short, read-only C# program that uses no keys at all. BSD Infotech is an independent ACS supplier and integrator, not the manufacturer.
Compiled by BSD; not yet tested on a reader. BSD Infotech built the C# code below for .NET 10 on 1 Dec 2026 with 0 warnings and 0 errors, and ran it on a PC without an ACS reader (it reported "no reader" as expected). The command sequence follows the ACS manuals and NXP's public documents, but BSD has not yet run it with a DESFire card. The checks still to be done are listed under what BSD still has to test.
Step 1: Detect a DESFire Card
Detection takes two checks, one from the reader and one from the card.
- The ATR. A DESFire card speaks ISO 14443-4, so an ACS reader builds a short ATR that starts
3B 8n 80 01and carries the card's historical bytes instead of a card name. The ACS manuals give3B 81 80 01 80 80(ACR1252U and ACR1552U) and3B 86 80 01 06 75 77 81 02 80 00(ACR122U) as DESFire examples. A MIFARE Classic, Ultralight or NTAG card gets the longer storage-card ATR3B 8F 80 01 80 4F …instead. Our smart card ATR guide decodes both and explains why two DESFire cards can give different ATRs. - GetVersion. The ATR only says "ISO 14443-4 card". NXP's identification note AN10833 recommends the card's own GetVersion command for exact identification, and GetVersion needs no key. In the first reply frame, the second byte is the hardware type: a lower half of
1means MIFARE DESFire, and8means MIFARE DESFire Light, a separate, simpler product. The fourth byte is the hardware major version, whose lower half AN10833 maps to EV1 (1), EV2 (2) and EV3 (3). The sixth byte is the storage size code, for example16= 2 KB,18= 4 KB,1A= 8 KB.
The third GetVersion frame starts with the 7-byte UID. When the card issuer has switched on the random ID option (available from EV1 on), the card sends a new random ID each time it is powered instead of its UID, and NXP's DESFire Light data sheet says the GetVersion UID field is then all zeros. The program below prints "hidden" in that case. For UID-only reading, use FF CA 00 00 00 as in our C# UID tutorial. The same two checks, done by hand, are step 4 of the MIFARE test guide's DESFire section.
How DESFire Commands Travel Through PC/SC
A native DESFire command is one command byte followed by its parameters. The card answers with one status byte followed by any data. For ISO 7816-4 software, the same command can be wrapped in an APDU with class 90:
Native: [command] [parameters] reply: [status] [data]
Wrapped: 90 [command] 00 00 [Lc] [parameters] 00 reply: [data] 91 [status]
(no parameters: 90 [command] 00 00 00)
So the native status 00 (OK) becomes the status word 91 00, and AF (more frames) becomes 91 AF. The ACR122U manual shows GetVersion both ways. Wrapped, it is 90 60 00 00 00, answered with 7 bytes and 91 AF. Send 90 AF 00 00 00 for the second frame (another 7 bytes and 91 AF) and again for the last one (14 bytes and 91 00). Native, the same exchange is 60, AF, AF, with the status byte at the start of each reply.
Three facts from the ACS and NXP documents decide how you should write your code:
- The first command fixes the mode. The ACR122U manual says that once the card is activated, the first command decides whether it talks native or wrapped, and the rest must follow the same format.
- Windows may already have chosen. The ACR1552U manual warns that Windows Smart Card Plug and Play can send an APDU when a card arrives, which puts a DESFire card into ISO APDU mode. Native commands then fail until the card is reset. Wrapped commands are not affected, so use the wrapped form in applications, as the code below does.
- Byte order. Multi-byte native parameters (application IDs, offsets, lengths, file sizes) are sent least significant byte first. NXP's public DESFire Light data sheet states this, and NXP's AN11004 examples follow it: application
000001is sent as01 00 00.
The reader does nothing DESFire-specific here. The ACR1552U manual says that for an ISO 14443-4 card the reader packs the command into the radio frame without interpreting it, and answers 6A 81 itself if the card does not support ISO 14443-4. That is the opposite of the FF commands used for MIFARE Classic, which the reader carries out on the card's behalf (background in ACS FF commands vs card APDUs). Every command code, framing option and status code is listed on our DESFire APDU commands reference.
Applications, Files and Access Rights
NXP's public DESFire EV2 short data sheet describes the card as a small file system. Knowing its three levels makes every reply easier to read:
| Level | What it holds | What reading it means |
|---|---|---|
Card (PICC) level, AID 00 00 00 | The card master key and card settings. It creates and deletes applications. | Selected after the card is activated. The list of applications is read here. |
| Application, 3-byte AID | Its own keys (up to 14) and settings, and its files. EV1 allows 28 applications per card; NXP lists no fixed limit for EV2 (only memory). | Select it, then list its files. Applications cannot see each other's files. |
| File, number 00 to 1F | Data. Types include standard data, backup data, value, linear record and cyclic record files. | Each file has its own access rights and communication mode. |
Access rights are four 4-bit conditions per file: Read, Write, Read&Write and Change (who may change the file's settings). Each condition is either a key number of the application, E = free access (no authentication) or F = no access. NXP's AN11004 uses exactly this coding: its NFC Type 4 Tag files have read access "free" (E). A file you can read without a key is one whose Read or Read&Write condition is E.
The communication mode (plain, MAC or fully encrypted) decides how data travels once a session with a key exists. NXP's DESFire Light data sheet says that free access uses plain communication, so a free-read file should return its data unprotected. BSD will confirm this on EV1 to EV3 cards (hardware check 3).
The Read Sequence, Command by Command
All commands below are wrapped (class 90, P1 P2 00 00, Le 00). None of them changes the card. The codes are from NXP's public command list in AN12752. Parameter layouts are from NXP's AN11004 examples and its public DESFire Light data sheet, as noted.
| Step | Command bytes | Reply on success | Can fail with |
|---|---|---|---|
1. GetVersion (60) | 90 60 00 00 00, then 90 AF 00 00 00 twice | 7 + 7 + 14 bytes, ending 91 00 | 6A 81 or 6E 00 on a card that is not a DESFire |
2. Select card level (5A) | 90 5A 00 00 03 00 00 00 00 | 91 00 | Rarely fails |
3. GetApplicationIDs (6A) | 90 6A 00 00 00 | 3 bytes per application, LSB first, then 91 00 (91 AF if there are more frames) | 91 AE if the card settings require the card master key for listing |
4. SelectApplication (5A) | 90 5A 00 00 03 [AID LSB first] 00, e.g. … 03 01 00 00 00 for 000001 | 91 00 | An error if the AID does not exist |
5. GetFileIDs (6F) | 90 6F 00 00 00 | 1 byte per file number, then 91 00 | 91 AE or 91 9D if the application settings require a key |
6. GetFileSettings (F5) | 90 F5 00 00 01 [file] 00 | Standard data file: type 00, communication mode, access rights (2 bytes), size (3 bytes), then 91 00 | 91 F0 (no such file), 91 AE or 91 9D |
7. ReadData (BD) | 90 BD 00 00 07 [file] [offset, 3 bytes] [length, 3 bytes] 00 | The data, then 91 00; longer reads come in several frames with 91 AF | 91 AE (key needed), 91 BE (beyond the end of the file), 91 9D |
Notes on the table. The access rights come as two bytes, least significant first, so in the reply bytes E0 EE (which NXP's AN11004 uses for its NDEF file) the second byte holds Read (E) and Write (E), and the first holds Read&Write (E) and Change (0, key 0). A length of 00 00 00 in ReadData means "to the end of the file". AN12752 lists two codes for ReadData, BD and AD. The public DESFire Light data sheet documents AD with the same parameters. This page and its code use BD. When to use each is explained in NXP's DESFire data sheet, which is available only under NDA.
// Example sequence for application 000001, file 01, first 32 bytes. Not yet tested on a reader.
90 60 00 00 00 GetVersion, frame 1 -> 7 bytes 91 AF
90 AF 00 00 00 GetVersion, frame 2 -> 7 bytes 91 AF
90 AF 00 00 00 GetVersion, frame 3 -> 14 bytes 91 00
90 5A 00 00 03 00 00 00 00 select card level -> 91 00
90 6A 00 00 00 list applications -> 01 00 00 ... 91 00
90 5A 00 00 03 01 00 00 00 select application 000001 -> 91 00
90 6F 00 00 00 list files -> 01 02 ... 91 00
90 F5 00 00 01 01 00 settings of file 01 -> 00 00 E0 EE ... 91 00
90 BD 00 00 07 01 00 00 00 20 00 00 00 read 32 bytes from file 01 -> data 91 00
What Needs Authentication, and Why
Three settings decide whether a read step works without a key:
- Card settings, controlled by the card master key, decide whether anyone may list the applications. NXP's AN11004 shows this as a setting an issuer can choose, so on one card
90 6Aworks and on another it returns91 AE. - Application settings, controlled by the application master key, decide whether the file list and file settings can be read without authentication. AN11004 shows both choices; its NFC Type 4 Tag application requires a key for GetFileIDs and GetFileSettings.
- File access rights decide who may read the data: free (
E), a numbered key, or no one.
When a key is needed, the application authenticates: a mutual three-pass authentication (NXP's wording) in which the card and the reader each prove that they know the same key without sending it. The exchange also creates session keys. After that, data for that application flows plain, with a MAC, or fully encrypted, as each file's communication mode says. DESFire EV1 and later support DES, 2-key and 3-key triple DES, and AES keys, and EV2 and EV3 add their own AES-based secure messaging. The authentication commands are named and compared, at concept level, in the authentication section of our DESFire command reference.
Why is it designed like this? Because a DESFire card often holds several services, for example access, canteen and transport, each owned by a different party. The keys keep each party's data private, and the access rights let an issuer leave harmless data (a card number, an NDEF message) readable by anyone while protecting the rest. A real reading application therefore needs the keys for the files it uses, and needs to keep those keys safe. Key diversification, key storage in a SAM or on a server, and why keys must never sit in client code are explained in our MIFARE authentication and key management guide.
What this page does not do. It does not authenticate, change keys, create or delete applications, or write data. It does not help anyone read a card they do not own or recover keys. On a factory-new DESFire card there are no applications yet, so the read sequence stops after step 3 with an empty list. To try a full read, use a test card on which you created, with your own tools, an application that allows free file listing and holds a free-read file.
Try It First in the ACS Tools
Before writing code, check the card and the reader by hand. It takes five minutes and tells you whether a problem is in your code or in the setup.
- ACS QuickView: read the ATR. Tap the card and check for a short ATR starting
3B 8n 80 01. How to install and read it: QuickView guide, reading the ATR. - ACS Script Tool: send the commands. Run the script below. The script format (one command per line, the expected status word in brackets) is explained in the Script Tool guide. The first five lines are the DESFire stage of our APDU test plan, which also lists the expected replies and failures.
- No-code alternative: the free BSD reader utilities for the ACR1552U and ACR1252U identify a DESFire card and show its UID. They work only with cards still on their factory keys and cannot change keys. Card identity is free; reading and writing card data needs a BSD licence key.
; desfire-read.txt (ACS Script Tool; read-only, no keys; not yet tested on hardware)
FF CA 00 00 00 (90 00)
90 60 00 00 00 (91 AF)
90 AF 00 00 00 (91 AF)
90 AF 00 00 00 (91 00)
90 5A 00 00 03 00 00 00 00 (91 00)
; list applications: 91 00 with 3 bytes per AID, or 91 AE if the card needs a key for this
90 6A 00 00 00
; then, by hand, with an AID from the list (LSB first) and a file number from 90 6F:
; 90 5A 00 00 03 01 00 00 00
; 90 6F 00 00 00
; 90 F5 00 00 01 01 00
; 90 BD 00 00 07 01 00 00 00 20 00 00 00
Do not add any other command to this script. Commands that create, delete, format or change keys can make a test card unusable. The Script Tool safety rules apply.
C# Project Setup (.NET 10)
Language: C# 14 on .NET 10, Windows only (P/Invoke to winscard.dll, no NuGet packages). You need: an ACS contactless reader with its driver installed and visible to PC/SC (check with our PC/SC reader status guide), and a DESFire test card you own. Never point it at a card from a live access, canteen, transport or payment system.
- Create the project as in the PC/SC programming in C# setup:
dotnet new console -n ReadDesfire, which targetsnet10.0with the .NET 10 SDK. - Add the two shared PC/SC files from that tutorial, unchanged: WinScard.cs and Pcsc.cs.
- Add
Desfire.csfrom the next section, and replaceProgram.cswith the program below. - Build:
dotnet build. Expected: Build succeeded, 0 errors. Run:dotnet run -- ACR1552 64to use the reader whose name contains "ACR1552" and show up to 64 bytes of each free file. With no arguments it uses the first reader whose name contains "PICC" and shows 32 bytes.
Desfire.cs: Wrapped, Read-Only Commands
This file builds the wrapped APDUs, follows 91 AF frames automatically, and decodes application IDs and file settings. Its Send method has an allow-list: it refuses any command code other than the six read commands and AF, so no authentication, write, create, delete, format or key command can be sent through it. It contains no key.
Compiled by BSD; not yet tested on a reader. Built for net10.0 with 0 warnings and 0 errors (nullable on, warnings as errors) on 1 Dec 2026. Its APDU building and parsing were also checked offline against NXP's AN11004 example bytes.
// Desfire.cs: read-only MIFARE DESFire helpers. Native DESFire commands are sent wrapped in
// ISO/IEC 7816-4 APDUs (CLA 90 INS=command P1 00 P2 00 [Lc data] Le 00), as the ACS reader manuals show.
// C# 14, .NET 10, Windows only. Needs WinScard.cs and Pcsc.cs. Compiled by BSD; not yet tested on a reader.
// Deliberately read-only and keyless: Send() refuses every command code that is not in ReadOnlyCommands,
// so no authentication, write, create, delete, format or key command can leave this file.
using System;
using System.Collections.Generic;
namespace Bsd.Pcsc;
/// <summary>A DESFire reply: all data frames joined, plus the final status word.</summary>
public sealed record DesfireReply(byte Sw1, byte Sw2, byte[] Data)
{
/// <summary>91 00: OPERATION_OK.</summary>
public bool Ok => Sw1 == 0x91 && Sw2 == 0x00;
public string StatusWord => $"{Sw1:X2} {Sw2:X2}";
}
/// <summary>What GetFileSettings says about a file (only the fields this sample uses).</summary>
public sealed record DesfireFileSettings(byte FileType, byte CommMode, int Read, int Write, int ReadWrite, int Change, int? Size)
{
/// <summary>Access condition Eh = free access (no authentication needed).</summary>
public bool FreeRead => Read == 0xE || ReadWrite == 0xE;
}
public static class Desfire
{
// Command codes as listed in NXP AN12752 (public), table 2.
public const byte GetVersion = 0x60;
public const byte GetApplicationIds = 0x6A;
public const byte SelectApplication = 0x5A;
public const byte GetFileIds = 0x6F;
public const byte GetFileSettings = 0xF5;
public const byte ReadData = 0xBD;
public const byte AdditionalFrame = 0xAF; // "send me the next frame" (reply status 91 AF)
/// <summary>The only command codes this sample will send. All of them only read.</summary>
public static readonly IReadOnlySet<byte> ReadOnlyCommands =
new HashSet<byte> { GetVersion, GetApplicationIds, SelectApplication, GetFileIds, GetFileSettings, ReadData, AdditionalFrame };
/// <summary>The PICC level (card level) application ID, 00 00 00.</summary>
public const int PiccLevel = 0x000000;
/// <summary>Wraps a native command: 90 [cmd] 00 00 [Lc data] 00. Without data: 90 [cmd] 00 00 00.</summary>
public static byte[] Wrap(byte command, byte[] data)
{
if (data.Length > 255) throw new ArgumentException("Short APDUs carry at most 255 data bytes.", nameof(data));
if (data.Length == 0) return [0x90, command, 0x00, 0x00, 0x00];
var apdu = new byte[data.Length + 6];
apdu[0] = 0x90; apdu[1] = command; apdu[2] = 0x00; apdu[3] = 0x00; apdu[4] = (byte)data.Length;
data.CopyTo(apdu, 5);
apdu[^1] = 0x00; // Le: always 00 for wrapped commands
return apdu;
}
/// <summary>Sends one read-only command and follows 91 AF ("additional frame") until the card stops.</summary>
public static DesfireReply Send(CardConnection card, byte command, params byte[] data)
{
if (!ReadOnlyCommands.Contains(command))
throw new InvalidOperationException($"Command {command:X2} is not one of this sample's read-only commands.");
var all = new List<byte>();
byte[] reply = card.Transmit(Wrap(command, data));
for (int frames = 1; ; frames++)
{
if (reply.Length < 2) return new DesfireReply(0x00, 0x00, all.ToArray());
byte sw1 = reply[^2], sw2 = reply[^1];
all.AddRange(reply[..^2]);
if (!(sw1 == 0x91 && sw2 == 0xAF) || frames >= 64)
return new DesfireReply(sw1, sw2, all.ToArray());
reply = card.Transmit(Wrap(AdditionalFrame, []));
}
}
/// <summary>Selects an application by its 3-byte AID. The AID goes least significant byte first.</summary>
public static DesfireReply Select(CardConnection card, int aid) =>
Send(card, SelectApplication, (byte)aid, (byte)(aid >> 8), (byte)(aid >> 16));
/// <summary>Splits a GetApplicationIDs reply into AIDs (3 bytes each, least significant byte first).</summary>
public static List<int> ParseAids(byte[] data)
{
var aids = new List<int>();
for (int i = 0; i + 2 < data.Length; i += 3) aids.Add(data[i] | data[i + 1] << 8 | data[i + 2] << 16);
return aids;
}
/// <summary>ReadData: file number, 3-byte offset, 3-byte length (all least significant byte first).</summary>
public static DesfireReply Read(CardConnection card, byte fileNo, int offset, int length) =>
Send(card, ReadData, fileNo,
(byte)offset, (byte)(offset >> 8), (byte)(offset >> 16),
(byte)length, (byte)(length >> 8), (byte)(length >> 16));
/// <summary>Decodes the common part of a GetFileSettings reply. Returns null for a layout this sample
/// does not decode (for example extra option bits set, which the full NXP data sheet explains).</summary>
public static DesfireFileSettings? ParseFileSettings(byte[] data)
{
if (data.Length < 4) return null;
byte fileType = data[0], option = data[1];
if ((option & 0xFC) != 0) return null; // only the communication-mode bits are decoded here
int access = data[2] | data[3] << 8; // 2 bytes, least significant byte first
int? size = fileType == 0x00 && data.Length >= 7 ? data[4] | data[5] << 8 | data[6] << 16 : null;
return new DesfireFileSettings(fileType, (byte)(option & 0x03),
Read: access >> 12 & 0xF, Write: access >> 8 & 0xF, ReadWrite: access >> 4 & 0xF, Change: access & 0xF, size);
}
public static string FileTypeName(byte type) => type switch
{
0x00 => "standard data file",
0x02 => "value file",
0x04 => "cyclic record file",
0x05 => "transaction MAC file",
_ => $"file type {type:X2} (see NXP's data sheet)"
};
public static string CommModeName(byte mode) => mode switch
{
0x01 => "MAC",
0x03 => "full (encrypted)",
_ => "plain"
};
/// <summary>"free", "never" or "key N" for one 4-bit access condition.</summary>
public static string AccessName(int condition) => condition switch
{
0xE => "free",
0xF => "never",
_ => $"key {condition:X}"
};
/// <summary>Meaning of a status word, from NXP's public data sheets and ISO/IEC 7816-4.</summary>
public static string Explain(byte sw1, byte sw2) => (sw1, sw2) switch
{
(0x91, 0x00) => "OK",
(0x91, 0xAF) => "more frames (should have been followed)",
(0x91, 0xAE) => "authentication error: this needs a key (not in this sample)",
(0x91, 0x9D) => "permission denied: not allowed in the current state",
(0x91, 0xF0) => "file not found",
(0x91, 0x40) => "no such key",
(0x91, 0x7E) => "length error",
(0x91, 0x9E) => "parameter error",
(0x91, 0xBE) => "boundary error: read beyond the end of the file",
(0x91, 0x1C) => "illegal command code",
(0x91, 0xCA) => "command aborted: an earlier chained command was not finished",
(0x91, 0xEE) => "memory error",
(0x91, _) => "DESFire error (see NXP's data sheet)",
(0x6A, 0x81) => "reader: card does not support ISO 14443-4 (not a DESFire)",
(0x6E, 0x00) or (0x6D, 0x00) => "card does not know this command (not a DESFire, or the card is in native mode)",
_ => "unexpected reply"
};
}
Why only standard data files are read: the file type codes NXP publishes in public documents are 00 (standard data), 02 (value), 04 (cyclic record) and 05 (transaction MAC). The read commands for value and record files (GetValue, ReadRecords) are outside this tutorial. ParseFileSettings also gives up when option bits other than the communication mode are set, because that layout is described only in NXP's NDA data sheet.
Program.cs: List and Read Without Keys
The program waits for a card, checks the ATR, identifies the card with GetVersion, lists the applications and their files, prints each file's access rights, and reads the first bytes of every standard data file whose read access is free. It stops cleanly wherever the card asks for a key.
// Day 45: read a MIFARE DESFire card in C# without any key: version, applications, files, and the
// contents of files whose read access is "free". C# 14, .NET 10, Windows only.
// Needs WinScard.cs, Pcsc.cs and Desfire.cs. Compiled by BSD; not yet tested on a reader.
// Read-only and keyless: it never authenticates and sends no write, create, delete, format or key command.
// Use it on your own test cards only.
// Usage: dotnet run -- [reader filter, default PICC] [max bytes per file, default 32], e.g. dotnet run -- ACR1552 64
using System;
using System.Linq;
using System.Threading;
using Bsd.Pcsc;
using var cts = new CancellationTokenSource();
Console.CancelKeyPress += (_, e) => { e.Cancel = true; cts.Cancel(); };
string filter = args.Length > 0 ? args[0] : "PICC";
int maxBytes = 32;
if (args.Length > 1 && (!int.TryParse(args[1], out maxBytes) || maxBytes is < 1 or > 240))
{
Console.WriteLine("Max bytes must be a number from 1 to 240.");
return 1;
}
try
{
using var pcsc = new PcscContext();
string? reader = pcsc.ListReaders().FirstOrDefault(r => r.Contains(filter, StringComparison.OrdinalIgnoreCase));
if (reader is null) { Console.WriteLine($"No reader whose name contains \"{filter}\". Use the contactless (PICC) reader."); return 1; }
Console.WriteLine($"Reader: {reader}");
// Wait up to 15 s for a card.
var state = new[] { PcscContext.NewState(reader) };
pcsc.WaitForChange(state, 0, cts.Token);
while ((state[0].dwEventState & WinScard.SCARD_STATE_PRESENT) == 0)
{
Console.WriteLine("Place a DESFire test card on the reader (15 s; Ctrl+C to stop)...");
PcscContext.Acknowledge(state);
if (!pcsc.WaitForChange(state, 15_000, cts.Token)) { Console.WriteLine("No card within 15 s."); return 2; }
}
using var card = pcsc.Connect(reader);
var (_, _, atr) = card.Status();
Console.WriteLine($"ATR: {Apdu.HexSpaced(atr)}");
// 1. A DESFire card gives the short ISO 14443-4 ATR 3B 8n 80 01 ... (not the storage-card ATR 3B 8F 80 01 80 4F ...).
bool iso14443_4 = atr.Length >= 5 && atr[0] == 0x3B && (atr[1] & 0xF0) == 0x80 && atr[2] == 0x80 && atr[3] == 0x01
&& !(atr.Length >= 6 && atr[4] == 0x80 && atr[5] == 0x4F);
if (!iso14443_4) { Console.WriteLine("Not an ISO 14443-4 card ATR, so not a DESFire. Nothing sent."); return 3; }
// 2. GetVersion (60, then AF twice): 7 bytes hardware, 7 bytes software, then UID and production data.
var version = Desfire.Send(card, Desfire.GetVersion);
if (!version.Ok || version.Data.Length < 14)
{
Console.WriteLine($"GetVersion: {version.StatusWord} ({Desfire.Explain(version.Sw1, version.Sw2)})");
return 3;
}
byte[] v = version.Data;
if ((v[1] & 0x0F) != 0x01)
{
Console.WriteLine($"GetVersion hardware type {v[1]:X2}: not a MIFARE DESFire (AN10833: lower nibble 1 = DESFire). Stopping.");
return 3;
}
string generation = (v[3] & 0x0F) switch { 1 => "EV1", 2 => "EV2", 3 => "EV3", _ => $"major version {v[3]:X2}" };
Console.WriteLine($"Card: MIFARE DESFire {generation}, storage code {v[5]:X2}, software {v[10]:X2}.{v[11]:X2}");
if (v.Length >= 21)
{
byte[] uid = v[14..21];
Console.WriteLine(uid.All(b => b == 0) ? "UID: hidden (random ID is on)" : $"UID: {Apdu.Hex(uid)}");
}
// 3. Card level: list the applications. On many issued cards this needs the card master key (91 AE).
var select = Desfire.Select(card, Desfire.PiccLevel);
Console.WriteLine($"Select card level (AID 000000): {select.StatusWord} ({Desfire.Explain(select.Sw1, select.Sw2)})");
var aidReply = Desfire.Send(card, Desfire.GetApplicationIds);
if (!aidReply.Ok)
{
Console.WriteLine($"GetApplicationIDs: {aidReply.StatusWord} ({Desfire.Explain(aidReply.Sw1, aidReply.Sw2)})");
Console.WriteLine("The card does not list its applications without a key. This sample stops here.");
return 4;
}
var aids = Desfire.ParseAids(aidReply.Data);
Console.WriteLine(aids.Count == 0 ? "Applications: none (a blank card)" : $"Applications: {string.Join(", ", aids.Select(a => a.ToString("X6")))}");
// 4. Per application: select it, list its files, read each file's settings, read free files.
foreach (int aid in aids)
{
var sel = Desfire.Select(card, aid);
Console.WriteLine($"\nApplication {aid:X6}: select {sel.StatusWord} ({Desfire.Explain(sel.Sw1, sel.Sw2)})");
if (!sel.Ok) continue;
var files = Desfire.Send(card, Desfire.GetFileIds);
if (!files.Ok) { Console.WriteLine($" GetFileIDs: {files.StatusWord} ({Desfire.Explain(files.Sw1, files.Sw2)})"); continue; }
if (files.Data.Length == 0) { Console.WriteLine(" No files."); continue; }
foreach (byte fileNo in files.Data)
{
var fs = Desfire.Send(card, Desfire.GetFileSettings, fileNo);
if (!fs.Ok) { Console.WriteLine($" File {fileNo:X2}: GetFileSettings {fs.StatusWord} ({Desfire.Explain(fs.Sw1, fs.Sw2)})"); continue; }
var s = Desfire.ParseFileSettings(fs.Data);
if (s is null) { Console.WriteLine($" File {fileNo:X2}: settings {Apdu.HexSpaced(fs.Data)} (layout not decoded by this sample)"); continue; }
Console.WriteLine($" File {fileNo:X2}: {Desfire.FileTypeName(s.FileType)}{(s.Size is int n ? $", {n} bytes" : "")}, " +
$"comm mode {Desfire.CommModeName(s.CommMode)}, read {Desfire.AccessName(s.Read)}, write {Desfire.AccessName(s.Write)}, " +
$"read&write {Desfire.AccessName(s.ReadWrite)}, change {Desfire.AccessName(s.Change)}");
if (s.FileType != 0x00 || s.Size is not int size) { Console.WriteLine(" Not read: this sample reads standard data files only."); continue; }
if (!s.FreeRead) { Console.WriteLine(" Not read: reading needs a key, and this sample has none."); continue; }
if (size == 0) { Console.WriteLine(" Empty file."); continue; }
int length = Math.Min(size, maxBytes);
var data = Desfire.Read(card, fileNo, 0, length);
Console.WriteLine(data.Ok
? $" First {data.Data.Length} bytes: {Apdu.HexSpaced(data.Data)}"
: $" ReadData: {data.StatusWord} ({Desfire.Explain(data.Sw1, data.Sw2)})");
}
}
return 0;
}
catch (OperationCanceledException)
{
Console.WriteLine("Stopped.");
return 130;
}
catch (PcscException ex)
{
Console.WriteLine(ex.Message); // e.g. 0x80100069 when the card was removed mid-read
return 1;
}
What the output looks like
An illustration of the format, not a captured result (BSD has not yet run it with a card). Values in angle brackets depend on your card:
Reader: <ACS reader name> PICC 0
ATR: 3B 81 80 01 80 80
Card: MIFARE DESFire EV<n>, storage code <18>, software <major>.<minor>
UID: <7 bytes>
Select card level (AID 000000): 91 00 (OK)
Applications: 000001
Application 000001: select 91 00 (OK)
File 01: standard data file, 32 bytes, comm mode plain, read free, write key 0, read&write key 0, change key 0
First 32 bytes: <data>
File 02: standard data file, 64 bytes, comm mode full (encrypted), read key 1, write key 1, read&write key 0, change key 0
Not read: reading needs a key, and this sample has none.
Exit codes: 0 = finished; 1 = no reader or a PC/SC error; 2 = no card within 15 s; 3 = not a DESFire card; 4 = the card does not list its applications without a key; 130 = stopped with Ctrl+C.
What BSD Still Has to Test
The tracker asks for this page to be tested with BSD's own test cards. Until these read-only checks are done, the code stays marked "not yet tested on a reader". None of them uses a key:
- ACR1552U and ACR1252U, factory-new DESFire card: GetVersion returns three frames (
91 AF,91 AF,91 00), the program names the right EV generation, and GetApplicationIDs returns an empty list. - ACR122U, the same card: the same results on the older reader.
- A test card with an application and a free-read standard file (prepared once by BSD with its own tools): the program lists the AID and file, decodes the access rights and reads the data with
BD. Also tryADby hand in the Script Tool and record the reply. - A file that needs a key: record whether GetFileSettings and ReadData reply
91 AEor91 9D. - Windows Plug and Play: run the program straight after tapping a fresh card, to confirm wrapped commands work when Windows has already sent an APDU.
- MIFARE Classic and NTAG cards: confirm the ATR check stops the program before any DESFire command is sent.
Troubleshooting
| What you see | Likely cause | What to do |
|---|---|---|
| "Not an ISO 14443-4 card ATR" | A MIFARE Classic, Ultralight or NTAG card, or the SAM reader entry was chosen | Use the PICC reader entry. Identify the card with the card identification step. |
GetVersion returns 6A 81 | The reader says the card does not support ISO 14443-4 | It is not a DESFire. Check the ATR in QuickView. |
Hardware type 08 | A MIFARE DESFire Light card | DESFire Light has one fixed application and no GetApplicationIDs; it uses ISO file selection. This sample stops. |
Native commands such as 60 fail on a fresh card | Windows Plug and Play put the card into ISO APDU mode | Use the wrapped form (90 60 00 00 00), or lift the card and present it again. |
GetApplicationIDs returns 91 AE | The card settings require the card master key to list applications | Expected on many issued cards. You need the issuer's key and authorisation. |
GetFileIDs returns 91 AE on an NDEF-formatted card | NXP's AN11004 Type 4 Tag settings require a key for listing files | NFC Type 4 Tag readers read such cards with ISO 7816-4 commands instead (ISOSelectFile, ISOReadBinary): see the ISO 7816-4 commands. |
ReadData returns 91 AE or 91 9D | The file's read access needs a key | Check the file's access rights with GetFileSettings. Without the key the data stays protected, by design. |
ReadData returns 91 BE | Offset plus length goes past the end of the file | Read the file size with GetFileSettings and read within it. |
SCardConnect failed: 0x8010000B | Another program (QuickView, Script Tool, a BSD utility) holds the card | Close the other tool and run again. |
SCardTransmit failed: 0x80100069 | Card removed during the exchange | Keep the card still and start again from GetVersion. |
The full list of 91 xx codes with NXP's meanings is in the DESFire status code table. Reader-side errors (0x8010…) are explained in the PC/SC error handling section.
Sources
Checked on 1 Dec 2026. ACS facts come from the ACS reader manuals (local copies from the ACS SDK kits); DESFire command codes, layouts and status codes come only from NXP documents that NXP marks "Company Public". Explanations are in BSD's own words.
- ACS, ACR122U Application Programming Interface, version 2.04, section 7.2 "How to access MIFARE DESFire tags (ISO 14443-4)": wrapped and native modes, GetVersion frame chaining, first command fixes the mode
- ACS, ACR1552U Series Reference Manual, version 1.05, section 5.3.2: commands passed to ISO 14443-4 cards without interpretation,
6A 81, the Windows Plug and Play note; DESFire ATR example in section 5.3.1 - ACS, ACR1252U Application Programming Interface, version 1.17: DESFire ATR example, listed on the ACR1252U product page
- NXP, AN12752 rev. 1.4 (24 July 2023), MIFARE DESFire EV3 feature and functionality comparison: command names and codes (table 2)
- NXP, AN10833 rev. 3.9 (15 Dec 2025), MIFARE type identification procedure: GetVersion hardware type, version and size bytes
- NXP, AN11004 rev. 2.4 (22 May 2013), MIFARE DESFire as Type 4 Tag: wrapped SelectApplication examples, access-right coding, card-level listing settings
- NXP, MF3D(H)x2 MIFARE DESFire EV2 short data sheet rev. 3.2 (12 June 2019): file system, applications, file types, authentication and communication modes
- NXP, MF2DL(H)x0 MIFARE DESFire Light data sheet rev. 3.3 (5 April 2019): byte order, GetVersion, GetFileIDs, GetFileSettings and ReadData layouts, access conditions, status words
BSD Infotech is an independent ACS supplier and integrator, not the manufacturer. ACS, the ACS logo, QuickView, Script Tool and ACS product names belong to Advanced Card Systems Ltd. MIFARE, MIFARE Classic, MIFARE DESFire and NTAG are trademarks of NXP B.V. Windows is a trademark of Microsoft Corporation.
