---
name: "mifare_application"
section: "3"
platform: "linux"
package: "libfreefare-doc"
version: "0.4.0-2.3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mifare_application"
---

# mifare\_application(3)

Mifare Applications Manipulation Functions

## NAME

**mifare\_application\_alloc**, **mifare\_application\_find**, **mifare\_application\_free**, **mifare\_application\_read**, **mifare\_application\_write** – Mifare Applications Manipulation Functions

## LIBRARY

Mifare card manipulation library (libfreefare, -lfreefare)

## SYNOPSIS

**#include \<freefare.h\>**

*MifareClassicSectorNumber \**\

**mifare\_application\_alloc**(*Mad mad*, *MadAid aid*, *size\_t size*);

*void*\

**mifare\_application\_free**(*Mad mad*, *MadAid aid*);

*MifareClassicSectorNumber \**\

**mifare\_application\_find**(*Mad mad*, *MadAid aid*);

*ssize\_t*\

**mifare\_application\_read**(*MifareTag tag*, *Mad mad*, *MadAid aid*, *void \*buf*, *size\_t nbytes*, *MifareClassicKey key*, *MifareClassicKeyType key\_type*);

*ssize\_t*\

**mifare\_application\_write**(*MifareTag tag*, *Mad mad*, *MadAid aid*, *const void \*buf*, *size\_t nbytes*, *MifareClassicKey key*, *MifareClassicKeyType key\_type*);

## DESCRIPTION

The **mifare\_application\_\***() functions facilitate management of applications in a Mifare Application Directory.

The **mifare\_application\_alloc**() function allocates enought sectors to store *size* bytes for the Application Identifier *aid* and returns the list of allocated sectors.

The list of the sectors previously allocated for *aid* in a *mad* can be requested using **mifare\_application\_find**().

An application can be removed from a *mad* using **mifare\_application\_free**().

The **mifare\_application\_read**() reads at most *nbytes* of the application identified by *aid* in the *mad* on the *tag* and copy them into *buf.* The function returns the amount of data it copied, or -1 on error.

The **mifare\_application\_write**() functions writes at most *nbytes* of *buf* in the application identified by *aid* on the *mad* of the *tag* and returns the quantity of data written, or -1 on error.

## IMPLEMENTATION NOTES

The **mifare\_application\_alloc**() function will try to avoid wasting space and might not allocate sectors sequentially if a large amount of space is requested and the target has sectors of different size.

The *nbytes* argument of **mifare\_application\_read**() and **mifare\_application\_write**() does not need to be aligned on blocks not sectors.

## RETURN VALUES

Unless stated otherwise, all functions return a value greater than or equal to *0* on success or *-1* on failure.

## SEE ALSO

[mad(3)](/mad/3.md), [mifare\_classic(3)](/mifare_classic/3.md)

## AUTHORS

Romain Tartiere ⟨romain@blogreen.org⟩ Romuald Conty ⟨romuald@libnfc.org⟩
