Scroll to navigation

MIFARE_CLASSIC(3) Library Functions Manual MIFARE_CLASSIC(3)

NAME

mifare_classic_connect, mifare_classic_disconnect, mifare_classic_authenticate, mifare_classic_read, mifare_classic_init_value, mifare_classic_read_value, mifare_classic_write, mifare_classic_increment, mifare_classic_decrement, mifare_classic_restore, mifare_classic_transfer, mifare_classic_get_trailer_block_permission, mifare_classic_get_data_block_permission, mifare_classic_format_sector, mifare_classic_trailer_block, mifare_classic_block_sector, mifare_classic_sector_first_block, mifare_classic_sector_block_count, mifare_classic_sector_last_blockMifare Classic Manipulation Functions

LIBRARY

Mifare card manipulation library (libfreefare, -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

The () set of functions allow manipulation of both Mifare Classic 1k and Mifare Classic 4k cards.

A given tag is activated using (), deactivation is performed with ().

After a successful connection, an authentication for a block using a key of type key_type (either MFC_KEY_A or MFC_KEY_B) using () is required for further operation.

Once successfuly authenticated, data of a block can be read using () and written using ().

Value-blocks can be easily accessed using the () and () functions. Additional functions are available for such blocks: () and () increment or decrement the value of the provided block by amount and store the result in the target's internal data register. The value in this register can also be loaded with the value from another block using (). Writing back the value of the target's internal data register to a block is requested using ().

Permissions for a data block can be fetched using (). The access permission to be checkf for key key_type is one of MCAB_R, MCAB_W, MCAB_I or MCAB_D; respectively for read, write, increment and decrement permissions.

() acts like mifare_classic_get_data_block_permission() but the available permissions are MCAB_READ_KEYA, MCAB_READ_KEYB, MCAB_READ_ACCESS_BITS, MCAB_WRITE_ACCESS_BITS, MCAB_READ_KEYB and MCAB_WRITE_KEYB.

A whole sector can be reset to factory defaults using ().

The () is a convenience function for building a trailer block block given a A key key_a; access bits for the blocks of the sector ab_0, ab_1 and ab_2; and a B key key_b.

The (), function returns the number of the sector holding block.

The (), (), () or the complement of the mifare_classic_block_sector() function and return various block-level information about the provided sector.

RETURN VALUES

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

SEE ALSO

freefare(3), mad(3)

AUTHORS

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

March 30, 2010 Debian