MIFARE_CLASSIC(3)
π NAME π
hiii bestie, welcome to mifare_classic(3) β the manual page for the Mifare Classic Manipulation Functions π this is the whole squad, no cap:
mifare_classic_connectmifare_classic_disconnectmifare_classic_authenticatemifare_classic_readmifare_classic_init_valuemifare_classic_read_valuemifare_classic_writemifare_classic_incrementmifare_classic_decrementmifare_classic_restoremifare_classic_transfermifare_classic_get_trailer_block_permissionmifare_classic_get_data_block_permissionmifare_classic_format_sectormifare_classic_trailer_blockmifare_classic_block_sectormifare_classic_sector_first_blockmifare_classic_sector_block_countmifare_classic_sector_last_block
β¨ LIBRARY β¨
Mifare card manipulation library, aka libfreefare, and you link it with -lfreefare π«Ά
πΈ SYNOPSIS πΈ
#include <freefare.h>
int
mifare_classic_connect(MifareTag tag);
int
mifare_classic_disconnect(MifareTag tag);
int
mifare_classic_authenticate(MifareTag tag,
const MifareClassicBlockNumber block, const MifareClassicKey key,
const MifareClassicKeyType key_type);
int
mifare_classic_read(MifareTag tag, const MifareClassicBlockNumber block,
MifareClassicBlock *data);
int
mifare_classic_init_value(MifareTag tag,
const MifareClassicBlockNumber block, const int32_t value,
const MifareClassicBlockNumber adr);
int
mifare_classic_read_value(MifareTag tag,
const MifareClassicBlockNumber block, int32_t *value,
MifareClassicBlockNumber *adr);
int
mifare_classic_write(MifareTag tag,
const MifareClassicBlockNumber block,
const MifareClassicBlock data);
int
mifare_classic_increment(MifareTag tag,
const MifareClassicBlockNumber block, const uint32_t amount);
int
mifare_classic_decrement(MifareTag tag,
const MifareClassicBlockNumber block, const uint32_t amount);
int
mifare_classic_restore(MifareTag tag,
const MifareClassicBlockNumber block);
int
mifare_classic_transfer(MifareTag tag,
const MifareClassicBlockNumber block);
int
mifare_classic_get_trailer_block_permission(MifareTag tag,
const MifareClassicBlockNumber block, const uint16_t permission,
const MifareClassicKeyType key_type);
int
mifare_classic_get_data_block_permission(MifareTag tag,
const MifareClassicBlockNumber block,
const unsigned char permission,
const MifareClassicKeyType key_type);
int
mifare_classic_format_sector(MifareTag tag,
const MifareClassicSectorNumber sector);
void
mifare_classic_trailer_block(MifareClassicBlock *block,
const MifareClassicKey key_a, const uint8_t ab_0,
const uint8_t ab_1, const uint8_t ab_2, const uint8_t ab_tb,
const uint8_t gpb, const MifareClassicKey key_b);
MifareClassicSectorNumber
mifare_classic_block_sector(MifareClassicBlockNumber block);
MifareClassicBlockNumber
mifare_classic_sector_first_block(MifareClassicSectorNumber sector);
size_t
mifare_classic_sector_block_count(MifareClassicSectorNumber sector);
MifareClassicBlockNumber
mifare_classic_sector_last_block(MifareClassicSectorNumber sector);
π DESCRIPTION π
okay so the whole mifare_classic_*() family is here to let you mess with both Mifare Classic 1k and Mifare Classic 4k cards. iconic behavior honestly.
- You activate a tag with
mifare_classic_connect(), and you deactivate it withmifare_classic_disconnect(). open and close, like a lil door πͺ - Once you're successfully connected, you still need to authenticate for a block using a key of type
key_typeβ which is eitherMFC_KEY_AorMFC_KEY_Bβ viamifare_classic_authenticate(). only then can you do literally anything else. - Once you're successfully authenticated, you can read a block's data with
mifare_classic_read()and write it withmifare_classic_write()π - Value-blocks are lowkey the easy ones β hit them with
mifare_classic_read_value()andmifare_classic_init_value(). There's more where that came from for these blocks:mifare_classic_increment()andmifare_classic_decrement()bump the value of the given block up or down byamount, and they stash the result in the target's internal data register. That register value can also be loaded from another block usingmifare_classic_restore(). And when you want to write the target's internal data register back out to a block, you ask for it withmifare_classic_transfer(). - Wanna know what you're allowed to do with a data block?
mifare_classic_get_data_block_permission(). The access permission you're checking for keykey_typeis one ofMCAB_R,MCAB_W,MCAB_IorMCAB_Dβ respectively read, write, increment and decrement permissions. the receipts, fr fr π§Ύ mifare_classic_get_trailer_block_permission()is givingmifare_classic_get_data_block_permission()energy, except the permissions available areMCAB_READ_KEYA,MCAB_READ_KEYB,MCAB_READ_ACCESS_BITS,MCAB_WRITE_ACCESS_BITS,MCAB_READ_KEYBandMCAB_WRITE_KEYB.- Reset a whole sector back to factory defaults with
mifare_classic_format_sector(). factory reset, but make it a sector π mifare_classic_trailer_block()is the convenience function for building a trailer block β you hand it a A keykey_a, the access bits for the blocks of the sectorab_0,ab_1andab_2, and a B keykey_b. and it just... builds it for you. king behavior π- The
mifare_classic_block_sector()function returns the number of the sector holdingblock. - Then
mifare_classic_sector_first_block(),mifare_classic_sector_block_count(),mifare_classic_sector_last_block()are the complement of themifare_classic_block_sector()function, and they return various block-level info about thesectoryou gave them.
β RETURN VALUES β
Unless it says otherwise, every single function here returns a value greater than or equal to 0 on success, or -1 on failure. that's it, that's the whole vibe check. π
π¦ SEE ALSO π¦
π AUTHORS π
- Romain Tartiere
<romain@blogreen.org> - Romuald Conty
<romuald@libnfc.org>
and that's the page bestie, no notes π
this one's from Debian, dated March 30, 2010, and it lives in the manual as MIFARE_CLASSIC(3) β go forth and manipulate some Mifare Classic cards, you've got this π«Άβ¨
π¦ where this page comes from
- debian bookworm: libfreefare-doc 0.4.0-2.1 Β· LGPL-3.0-or-later
- debian trixie: libfreefare-doc 0.4.0-2.3 Β· LGPL-3.0-or-later
- nixos 26.05: libfreefare 0.4.0
- nixpkgs unstable: libfreefare 0.4.0
- ubuntu jammy: libfreefare-doc 0.4.0-2.1build1 Β· LGPL-3.0-or-later
- ubuntu noble: libfreefare-doc 0.4.0-2.3build2 Β· LGPL-3.0-or-later
- ubuntu questing: libfreefare-doc 0.4.0-2.3build2
- ubuntu resolute: libfreefare-doc 0.4.0-2.3build3 Β· LGPL-3.0-or-later
- ubuntu stonking: libfreefare-doc 0.4.0-2.4build1 Β· LGPL-3.0-or-later
- Copyright (C) 2010 Romain Tartiere
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms