C API for BALTECH SDK
mif.h File Reference
#include "../typedefs.h"

Go to the source code of this file.

Macros

#define BRP_Mif_ErrNoTag   BRP_ERR_STATUS(0x1000, 0x01)
 
#define BRP_Mif_ErrCrc   BRP_ERR_STATUS(0x1000, 0x02)
 
#define BRP_Mif_ErrAuth   BRP_ERR_STATUS(0x1000, 0x04)
 
#define BRP_Mif_ErrParity   BRP_ERR_STATUS(0x1000, 0x05)
 
#define BRP_Mif_ErrCode   BRP_ERR_STATUS(0x1000, 0x06)
 
#define BRP_Mif_ErrSnr   BRP_ERR_STATUS(0x1000, 0x08)
 
#define BRP_Mif_ErrKey   BRP_ERR_STATUS(0x1000, 0x09)
 
#define BRP_Mif_ErrNotauth   BRP_ERR_STATUS(0x1000, 0x0A)
 
#define BRP_Mif_ErrBitcount   BRP_ERR_STATUS(0x1000, 0x0B)
 
#define BRP_Mif_ErrBytecount   BRP_ERR_STATUS(0x1000, 0x0C)
 
#define BRP_Mif_VcsAndProxCheckError   BRP_ERR_STATUS(0x1000, 0x0E)
 
#define BRP_Mif_ErrWrite   BRP_ERR_STATUS(0x1000, 0x0F)
 
#define BRP_Mif_ErrInc   BRP_ERR_STATUS(0x1000, 0x10)
 
#define BRP_Mif_ErrDecr   BRP_ERR_STATUS(0x1000, 0x11)
 
#define BRP_Mif_ErrRead   BRP_ERR_STATUS(0x1000, 0x12)
 
#define BRP_Mif_ErrOvfl   BRP_ERR_STATUS(0x1000, 0x13)
 
#define BRP_Mif_ErrFraming   BRP_ERR_STATUS(0x1000, 0x15)
 
#define BRP_Mif_ErrBreak   BRP_ERR_STATUS(0x1000, 0x16)
 
#define BRP_Mif_ErrCmd   BRP_ERR_STATUS(0x1000, 0x17)
 
#define BRP_Mif_ErrColl   BRP_ERR_STATUS(0x1000, 0x18)
 
#define BRP_Mif_ErrReaderChipCommunication   BRP_ERR_STATUS(0x1000, 0x1A)
 
#define BRP_Mif_ErrFirmwareNotSupported   BRP_ERR_STATUS(0x1000, 0x1D)
 
#define BRP_Mif_ErrVal   BRP_ERR_STATUS(0x1000, 0x1E)
 
#define BRP_Mif_ErrIntegrity   BRP_ERR_STATUS(0x1000, 0x1F)
 
#define BRP_Mif_CondNotvalid   BRP_ERR_STATUS(0x1000, 0x20)
 
#define BRP_Mif_ErrHwNotSupported   BRP_ERR_STATUS(0x1000, 0x21)
 
#define BRP_Mif_ErrSamUnlock   BRP_ERR_STATUS(0x1000, 0x22)
 
#define BRP_Mif_ErrSamCommunication   BRP_ERR_STATUS(0x1000, 0x23)
 

Functions

brp_errcode brp_Mif_LoadKey (brp_protocol protocol, unsigned KeyIdx, brp_buf Key)
 
brp_errcode brp_Mif_Request (brp_protocol protocol, unsigned ReqAll, unsigned *ATQA)
 
brp_errcode brp_Mif_Anticoll (brp_protocol protocol, unsigned BitCount, brp_buf PreSelSer, brp_buf *Snr, brp_mempool *mempool)
 
brp_errcode brp_Mif_Select (brp_protocol protocol, brp_buf Snr, unsigned *SAK)
 
brp_errcode brp_Mif_AuthE2 (brp_protocol protocol, unsigned AuthMode, unsigned Block, unsigned KeyIdx)
 
brp_errcode brp_Mif_AuthUser (brp_protocol protocol, unsigned AuthMode, unsigned Block, brp_buf Key)
 
brp_errcode brp_Mif_Read (brp_protocol protocol, unsigned Block, brp_buf *BlockData, brp_mempool *mempool)
 
brp_errcode brp_Mif_Write (brp_protocol protocol, unsigned Block, brp_buf BlockData)
 
brp_errcode brp_Mif_ChangeValue (brp_protocol protocol, unsigned Mode, unsigned Block, unsigned Value)
 
brp_errcode brp_Mif_ChangeValueBackup (brp_protocol protocol, unsigned Mode, unsigned Block, unsigned Value)
 
brp_errcode brp_Mif_TransferBlock (brp_protocol protocol, unsigned Block)
 
brp_errcode brp_Mif_Halt (brp_protocol protocol)
 
brp_errcode brp_Mif_AuthE2Extended (brp_protocol protocol, unsigned AuthLevel, bool KeyHasExtIdx, unsigned EV1Mode, bool IsKeyB, unsigned Block, unsigned KeyIdx, unsigned KeyExtIdx, brp_buf DivData, size_t DivData_len)
 
brp_errcode brp_Mif_AuthUserExtended (brp_protocol protocol, unsigned AuthLevel, unsigned EV1Mode, unsigned KeyB, unsigned Block, brp_buf Key, size_t Key_len)
 
brp_errcode brp_Mif_ResetAuth (brp_protocol protocol)
 
brp_errcode brp_Mif_ReadSL3 (brp_protocol protocol, unsigned NoMacOnCmd, unsigned PlainData, unsigned NoMacOnResp, unsigned Block, unsigned BlockNr, brp_buf *BlockData, size_t *BlockData_len, brp_mempool *mempool)
 
brp_errcode brp_Mif_WriteSL3 (brp_protocol protocol, unsigned PlainData, unsigned NoMacOnResp, unsigned Block, brp_buf BlockData, size_t BlockData_len)
 
brp_errcode brp_Mif_ChangeAESKey (brp_protocol protocol, bool KeyHasExtIdx, unsigned NoMacOnResp, unsigned Block, unsigned KeyIdx, unsigned KeyExtIdx, brp_buf DivData, size_t DivData_len)
 
brp_errcode brp_Mif_ValueSL3 (brp_protocol protocol, unsigned NoMacOnResp, unsigned Cmd, unsigned Block, unsigned DestBlock, unsigned Value, brp_buf *TMCounterTMValue, size_t *TMCounterTMValue_len, brp_mempool *mempool)
 
brp_errcode brp_Mif_ProxCheck (brp_protocol protocol, unsigned M, unsigned DisableIsoWrapping, bool UseExtProxKey, bool DiversifyProxKey, bool UseProxKey, unsigned ProxKeyIdx, brp_buf DivData, size_t DivData_len, brp_buf ProxKey, size_t ProxKey_len)
 
brp_errcode brp_Mif_GetCardVersion (brp_protocol protocol, brp_buf *CardVersion, size_t *CardVersion_len, brp_mempool *mempool)
 
brp_errcode brp_Mif_ReadSig (brp_protocol protocol, brp_buf *NxpSignature, size_t *NxpSignature_len, brp_mempool *mempool)
 
brp_errcode brp_Mif_VirtualCardSelect (brp_protocol protocol, bool ForceVcsAuthentication, bool UseExtVcSelectKeys, unsigned DiversifyMacKey, bool DiversifyEncKey, bool UseVcSelectKeys, brp_buf IID, size_t IID_len, unsigned EncKeyIdx, unsigned MacKeyIdx, brp_buf DivData, size_t DivData_len, brp_buf EncKey, size_t EncKey_len, brp_buf MacKey, size_t MacKey_len, unsigned *FciType, brp_buf *Fci, size_t *Fci_len, brp_mempool *mempool)
 
brp_errcode brp_Mif_SectorSwitch (brp_protocol protocol, bool L3SectorSwitch, unsigned SectorSwitchKeyIdx, brp_buf SectorSwitchKeyDivData, size_t SectorSwitchKeyDivData_len, brp_Mif_SectorSwitch_SectorSpec_Entry *SectorSpec, size_t SectorSpec_len, brp_buf SectorKeysDivData, size_t SectorKeysDivData_len)
 
brp_errcode brp_Mif_CommitReaderID (brp_protocol protocol, unsigned Block, brp_buf *EncTRI, size_t *EncTRI_len, brp_mempool *mempool)
 
brp_errcode brp_Mif_SetFraming (brp_protocol protocol, brp_Mif_SetFraming_CommMode CommMode)
 

Detailed Description

With this command group, you can access MIFARE cards in low-level mode.

Whenever a card enters the HF field, it will be in idle state. From the idle state, a card switches to the requested state as soon as the Mif.Request command is executed. Cards in requested state participate in the anti-collision sequence, controlled by the Mif.Anticoll command, resulting in an unambiguous serial number belonging to one of the cards in the HF field. The card with this serial number may now be selected with the Mif.Select command. All other cards will fall back to idle state again and wait for the next call of the Mif.Request command. The selected card, however, changes from requested state to selected state.

TheMif.Anticoll andMif.Select commands can only process serial numbers with a length of 4 bytes. Since 2010, however, MIFARE cards with a 7-byte serial number are available. Please use theISO14443-3 (Type A) command group" to select and process cards with 7-byte serial numbers.

When a card is in selected state, communication with the card is possible. Nevertheless, it is necessary to be authenticated before a sector of the card can be accessed. Authentication can be performed either with the Mif.AuthE2 command or with the Mif.AuthUser command. Both commands send a key to the currently selected card along with information regarding whether this key should be compared to key A or key B on the card. If the given key matches the corresponding sector's key (either key A or key B, as specified in the command's parameters), then access according to the access conditions of the desired sector will be granted.

Finally, a card that is in select state can be set to halt state. A card in halt state will not respond to any command unless a specially parameterized Mif.Request command is called, or when it leaves and then re- enters the HF field of the reader's antenna. The halt state is helpful when it is necessary to deal with multiple cards present in the reader's antenna HF field.

The Mif.Read and Mif.Write commands can be use to read/write data from/to a certain block. Additionally, a data sector may be turned into a special value sector (also called value block), which is initialized with a specific starting value and can then only be changed by means of increment and decrement operations using the ChangeValue or ChangeValueBackup commands. Value sectors are very useful in some scenarios, such as for cash-based applications. To create a value sector, it is simply required to write specially formatted data to it:

  • The first 4 bytes (bytes 0-3) represent the initially stored value.
  • The following 4 bytes (bytes 4-7) have to be the two's complement of the first 4 bytes.
  • The next 4 bytes (bytes 8-11) are a copy of the first 4 bytes.
  • The last 4 bytes (bytes 12-15) contain the 1-byte address of a block which can be used for backup management. This address is stored on both byte 12 and byte 14, while its two's complement is stored on both byte 13 and byte 15. These 4 bytes are not affected by calls of the Mif.ChangeValue and Mif.ChangeValueBackup commands.

Each increment and decrement operation has to be followed by a transfer operation, using the Mif.TransferBlock command, in order to make the increment/decrement persistent. This feature guarantees that no data will be lost during a recalculation of the value on the card.

Definition in file mif.h.