Provided by: libfreefare-doc_0.4.0-2.3build2_all bug

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_block — Mifare 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 mifare_classic_*() set of functions allow manipulation of both Mifare Classic 1k and
     Mifare Classic 4k cards.

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

     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 mifare_classic_authenticate() is required for further
     operation.

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

     Value-blocks can be easily accessed using the mifare_classic_read_value() and
     mifare_classic_init_value() functions. Additional functions are available for such blocks:
     mifare_classic_increment() and mifare_classic_decrement() 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
     mifare_classic_restore().  Writing back the value of the target's internal data register to
     a block is requested using mifare_classic_transfer().

     Permissions for a data block can be fetched using
     mifare_classic_get_data_block_permission().  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.

     mifare_classic_get_trailer_block_permission() 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 mifare_classic_format_sector().

     The mifare_classic_trailer_block() 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 mifare_classic_block_sector(), function returns the number of the sector holding block.

     The mifare_classic_sector_first_block(), mifare_classic_sector_block_count(),
     mifare_classic_sector_last_block() 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>