LibLogicalAccess  2.5.0
An Open Source RFID Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
logicalaccess::MifareCommands Class Referenceabstract

The Mifare commands class. More...

#include <mifarecommands.hpp>

Inheritance diagram for logicalaccess::MifareCommands:
logicalaccess::Commands logicalaccess::ICommands logicalaccess::MifareOK5553Commands logicalaccess::MifarePCSCCommands logicalaccess::MifarePlusSL1Commands logicalaccess::MifareSTidSTRCommands logicalaccess::MifareACR1222LCommands logicalaccess::MifareCL1356Commands logicalaccess::MifareCherryCommands logicalaccess::MifareOmnikeyXX21Commands logicalaccess::MifareSCMCommands logicalaccess::MifareSpringCardCommands logicalaccess::MifarePlusSL1Policy< MifareSL1Impl, MifareClassicImpl > logicalaccess::MifarePlusACSACR1222L_SL1Commands logicalaccess::MifarePlusOmnikeyXX21SL1Commands logicalaccess::MifarePlusSpringcardAES_SL1_Auth logicalaccess::MifarePlusSpringcardSL1Commands

Public Member Functions

 MifareCommands ()
 
 MifareCommands (std::string ct)
 
virtual ByteVector readSector (int sector, int start_block, std::shared_ptr< MifareKey > keyA, std::shared_ptr< MifareKey > keyB, const MifareAccessInfo::SectorAccessBits &sab, bool readtrailer=false) final
 
virtual void writeSector (int sector, int start_block, const ByteVector &buf, std::shared_ptr< MifareKey > keyA, std::shared_ptr< MifareKey > keyB, const MifareAccessInfo::SectorAccessBits &sab, unsigned char userbyte=0x00, MifareAccessInfo::SectorAccessBits *newsab=nullptr, std::shared_ptr< MifareKey > newkeyA=std::shared_ptr< MifareKey >(), std::shared_ptr< MifareKey > newkeyB=std::shared_ptr< MifareKey >()) final
 
virtual ByteVector readSectors (int start_sector, int stop_sector, int start_block, std::shared_ptr< MifareKey > keyA, std::shared_ptr< MifareKey > keyB, const MifareAccessInfo::SectorAccessBits &sab) final
 
virtual void writeSectors (int start_sector, int stop_sector, int start_block, const ByteVector &buf, std::shared_ptr< MifareKey > keyA, std::shared_ptr< MifareKey > keyB, const MifareAccessInfo::SectorAccessBits &sab, unsigned char userbyte=0x00, MifareAccessInfo::SectorAccessBits *newsab=nullptr, std::shared_ptr< MifareKey > newkeyA=std::shared_ptr< MifareKey >(), std::shared_ptr< MifareKey > newkeyB=std::shared_ptr< MifareKey >()) final
 
unsigned int getSectorFromMAD (long aid, std::shared_ptr< MifareKey > madKeyA)
 Get the sector referenced by the AID from the MAD.
 
void setSectorToMAD (long aid, unsigned int sector, std::shared_ptr< MifareKey > madKeyA, std::shared_ptr< MifareKey > madKeyB)
 Set the sector referenced by the AID to the MAD.
 
void authenticate (std::shared_ptr< Location > location, std::shared_ptr< AccessInfo > ai, bool write=false)
 Authenticate on a given location.
 
void changeKeys (MifareKeyType keytype, std::shared_ptr< MifareKey > key, std::shared_ptr< MifareKey > newkeyA, std::shared_ptr< MifareKey > newkeyB, unsigned int sector, MifareAccessInfo::SectorAccessBits *newsab, unsigned char userbyte=0x00)
 
void changeKeys (std::shared_ptr< MifareKey > newkeyA, std::shared_ptr< MifareKey > newkeyB, unsigned int sector, MifareAccessInfo::SectorAccessBits *newsab, unsigned char userbyte=0x00)
 
void authenticate (MifareKeyType keyType, std::shared_ptr< MifareKey > key, int sector, int block, bool write)
 Authenticate for a targeted block.
 
virtual ByteVector readBinary (unsigned char blockno, size_t len)=0
 Read bytes from the card.
 
virtual void updateBinary (unsigned char blockno, const ByteVector &buf)=0
 Write bytes to the card.
 
virtual bool loadKey (unsigned char keyno, MifareKeyType keytype, std::shared_ptr< MifareKey > key, bool vol=false)=0
 Load a key to the reader.
 
virtual void loadKey (std::shared_ptr< Location > location, MifareKeyType keytype, std::shared_ptr< MifareKey > key)=0
 Load a key on a given location.
 
virtual void authenticate (unsigned char blockno, unsigned char keyno, MifareKeyType keytype)=0
 Authenticate a block, given a key number.
 
virtual void authenticate (unsigned char blockno, std::shared_ptr< KeyStorage > key_storage, MifareKeyType keytype)=0
 Authenticate a block, given a key number.
 
virtual void increment (uint8_t blockno, uint32_t value)=0
 
virtual void decrement (uint8_t blockno, uint32_t value)=0
 
bool writeValueBlock (uint8_t blockno, int32_t value, uint8_t backup_blockno)
 
bool readValueBlock (uint8_t blockno, int32_t &value, uint8_t &backup_block)
 
- Public Member Functions inherited from logicalaccess::Commands
 Commands ()=delete
 Constructor.
 
virtual ~Commands ()
 
std::shared_ptr< ChipgetChip () const override
 Get the chip.
 
virtual void setChip (std::shared_ptr< Chip > chip)
 Set the chip.
 
std::shared_ptr< ReaderCardAdaptergetReaderCardAdapter () const override
 Get the reader/card adapter.
 
virtual void setReaderCardAdapter (std::shared_ptr< ReaderCardAdapter > adapter)
 Set the reader/card adapter.
 
virtual const std::string & getCmdType () const
 Get the cmd name.
 
virtual void setCmdType (const std::string &command_type)
 Set the cmd name.
 
- Public Member Functions inherited from logicalaccess::ICommands
virtual ~ICommands ()=default
 
virtual std::shared_ptr< ChipgetChip () const =0
 Get the chip.
 
virtual std::shared_ptr< ReaderCardAdaptergetReaderCardAdapter () const =0
 Get the reader/card adapter.
 

Static Public Member Functions

static unsigned char calculateMADCrc (const unsigned char *madbuf, size_t madbuflen)
 Calculate the MAD crc.
 
static unsigned int findReferencedSector (long aid, unsigned char *madbuf, size_t madbuflen)
 Find the referenced sector in the MAD.
 
static MifareKeyType getKeyType (const MifareAccessInfo::SectorAccessBits &sab, int sector, int block, bool write)
 
static unsigned char getNbBlocks (int sector)
 Get number of data blocks for a sector.
 
static unsigned char getSectorStartBlock (int sector)
 Get the sector start block.
 

Protected Member Functions

std::shared_ptr< MifareChipgetMifareChip () const
 
- Protected Member Functions inherited from logicalaccess::Commands
 Commands (std::string commandtype)
 Constructor.
 

Additional Inherited Members

- Protected Attributes inherited from logicalaccess::Commands
std::shared_ptr< ReaderCardAdapterd_readerCardAdapter
 The reader/card adapter.
 
std::weak_ptr< Chipd_chip
 The chip.
 
std::string d_commandtype
 The command type.
 

Detailed Description

The Mifare commands class.

Constructor & Destructor Documentation

◆ MifareCommands() [1/2]

logicalaccess::MifareCommands::MifareCommands ( )
inline

◆ MifareCommands() [2/2]

logicalaccess::MifareCommands::MifareCommands ( std::string  ct)
inlineexplicit

Member Function Documentation

◆ authenticate() [1/4]

void logicalaccess::MifareCommands::authenticate ( MifareKeyType  keyType,
std::shared_ptr< MifareKey key,
int  sector,
int  block,
bool  write 
)

Authenticate for a targeted block.

Parameters
keyTypeThe key type.
keyThe authentication key.
sectorThe sector.
blockThe block.
writeWrite access.

◆ authenticate() [2/4]

void logicalaccess::MifareCommands::authenticate ( std::shared_ptr< Location location,
std::shared_ptr< AccessInfo ai,
bool  write = false 
)

Authenticate on a given location.

Parameters
locationThe location.
aiThe access infos.

◆ authenticate() [3/4]

virtual void logicalaccess::MifareCommands::authenticate ( unsigned char  blockno,
std::shared_ptr< KeyStorage key_storage,
MifareKeyType  keytype 
)
pure virtual

Authenticate a block, given a key number.

Parameters
blocknoThe block number.
key_storageThe key storage used for authentication.
keytypeThe key type.

Implemented in logicalaccess::MifarePlusSL1Commands, logicalaccess::MifarePlusSL1Policy< MifareSL1Impl, MifareClassicImpl >, logicalaccess::MifareOK5553Commands, logicalaccess::MifarePCSCCommands, logicalaccess::MifareSpringCardCommands, and logicalaccess::MifareSTidSTRCommands.

◆ authenticate() [4/4]

virtual void logicalaccess::MifareCommands::authenticate ( unsigned char  blockno,
unsigned char  keyno,
MifareKeyType  keytype 
)
pure virtual

◆ calculateMADCrc()

unsigned char logicalaccess::MifareCommands::calculateMADCrc ( const unsigned char *  madbuf,
size_t  madbuflen 
)
static

Calculate the MAD crc.

Parameters
madbufThe MAD buffer.
madbuflenThe MAD buffer length.
Returns
The CRC.

◆ changeKeys() [1/2]

void logicalaccess::MifareCommands::changeKeys ( MifareKeyType  keytype,
std::shared_ptr< MifareKey key,
std::shared_ptr< MifareKey newkeyA,
std::shared_ptr< MifareKey newkeyB,
unsigned int  sector,
MifareAccessInfo::SectorAccessBits newsab,
unsigned char  userbyte = 0x00 
)

◆ changeKeys() [2/2]

void logicalaccess::MifareCommands::changeKeys ( std::shared_ptr< MifareKey newkeyA,
std::shared_ptr< MifareKey newkeyB,
unsigned int  sector,
MifareAccessInfo::SectorAccessBits newsab,
unsigned char  userbyte = 0x00 
)

◆ decrement()

virtual void logicalaccess::MifareCommands::decrement ( uint8_t  blockno,
uint32_t  value 
)
pure virtual

Decrement (inplace) the value block at address blockno by value unit.

This means that this is the equivalent of also calling transfer.

Warning
While the parameter is unsigned (because negative value causes errors), value superior to 2^31-1 are also rejected.

Implemented in logicalaccess::MifarePlusSL1Commands, logicalaccess::MifarePlusSL1Policy< MifareSL1Impl, MifareClassicImpl >, logicalaccess::MifareACR1222LCommands, logicalaccess::MifareCL1356Commands, logicalaccess::MifareOmnikeyXX21Commands, and logicalaccess::MifarePCSCCommands.

◆ findReferencedSector()

unsigned int logicalaccess::MifareCommands::findReferencedSector ( long  aid,
unsigned char *  madbuf,
size_t  madbuflen 
)
static

Find the referenced sector in the MAD.

Parameters
aidThe application ID.
madbufThe MAD buffer.
madbuflenThe MAD buffer length.

◆ getKeyType()

MifareKeyType logicalaccess::MifareCommands::getKeyType ( const MifareAccessInfo::SectorAccessBits sab,
int  sector,
int  block,
bool  write 
)
static

◆ getMifareChip()

std::shared_ptr< MifareChip > logicalaccess::MifareCommands::getMifareChip ( ) const
protected

◆ getNbBlocks()

unsigned char logicalaccess::MifareCommands::getNbBlocks ( int  sector)
static

Get number of data blocks for a sector.

Parameters
sectorThe sector.
Returns
The number of blocks.

◆ getSectorFromMAD()

unsigned int logicalaccess::MifareCommands::getSectorFromMAD ( long  aid,
std::shared_ptr< MifareKey madKeyA 
)

Get the sector referenced by the AID from the MAD.

Parameters
aidThe application ID.
madKeyAThe MAD key A for read access.
Returns
The sector.

◆ getSectorStartBlock()

unsigned char logicalaccess::MifareCommands::getSectorStartBlock ( int  sector)
static

Get the sector start block.

Parameters
sectorThe sector.
Returns
The first block for this sector.

◆ increment()

virtual void logicalaccess::MifareCommands::increment ( uint8_t  blockno,
uint32_t  value 
)
pure virtual

Increment (inplace) the value block at address blockno.

This means that this is the equivalent of also calling transfer.

Warning
While the parameter is unsigned (because negative value causes errors), value superior to 2^31-1 are also rejected.

Implemented in logicalaccess::MifarePlusSL1Commands, logicalaccess::MifarePlusSL1Policy< MifareSL1Impl, MifareClassicImpl >, logicalaccess::MifareACR1222LCommands, logicalaccess::MifareCL1356Commands, logicalaccess::MifareOmnikeyXX21Commands, and logicalaccess::MifarePCSCCommands.

◆ loadKey() [1/2]

virtual void logicalaccess::MifareCommands::loadKey ( std::shared_ptr< Location location,
MifareKeyType  keytype,
std::shared_ptr< MifareKey key 
)
pure virtual

◆ loadKey() [2/2]

virtual bool logicalaccess::MifareCommands::loadKey ( unsigned char  keyno,
MifareKeyType  keytype,
std::shared_ptr< MifareKey key,
bool  vol = false 
)
pure virtual

Load a key to the reader.

Parameters
keynoThe reader key slot number. Can be anything from 0x00 to 0x1F.
keytypeThe key type.
keyThe key.
volUse volatile memory.
Returns
true on success, false otherwise.

Implemented in logicalaccess::MifarePlusSL1Commands, logicalaccess::MifarePlusSL1Policy< MifareSL1Impl, MifareClassicImpl >, logicalaccess::MifareOK5553Commands, logicalaccess::MifareCherryCommands, logicalaccess::MifarePCSCCommands, logicalaccess::MifareSCMCommands, logicalaccess::MifareSpringCardCommands, logicalaccess::MifareSpringCardCommands, and logicalaccess::MifareSTidSTRCommands.

◆ readBinary()

virtual ByteVector logicalaccess::MifareCommands::readBinary ( unsigned char  blockno,
size_t  len 
)
pure virtual

Read bytes from the card.

Parameters
blocknoThe block number.
lenThe count of bytes to read. (0 <= len < 16)
Returns
The count of bytes red.

Implemented in logicalaccess::MifarePlusSL1Commands, logicalaccess::MifarePlusSL1Policy< MifareSL1Impl, MifareClassicImpl >, logicalaccess::MifareOK5553Commands, logicalaccess::MifarePCSCCommands, and logicalaccess::MifareSTidSTRCommands.

◆ readSector()

ByteVector logicalaccess::MifareCommands::readSector ( int  sector,
int  start_block,
std::shared_ptr< MifareKey keyA,
std::shared_ptr< MifareKey keyB,
const MifareAccessInfo::SectorAccessBits sab,
bool  readtrailer = false 
)
finalvirtual

◆ readSectors()

ByteVector logicalaccess::MifareCommands::readSectors ( int  start_sector,
int  stop_sector,
int  start_block,
std::shared_ptr< MifareKey keyA,
std::shared_ptr< MifareKey keyB,
const MifareAccessInfo::SectorAccessBits sab 
)
finalvirtual

◆ readValueBlock()

bool logicalaccess::MifareCommands::readValueBlock ( uint8_t  blockno,
int32_t &  value,
uint8_t &  backup_block 
)

Read the value and the address of the backup block from a value-block.

If the block is not a valid value block, return false.

◆ setSectorToMAD()

void logicalaccess::MifareCommands::setSectorToMAD ( long  aid,
unsigned int  sector,
std::shared_ptr< MifareKey madKeyA,
std::shared_ptr< MifareKey madKeyB 
)

Set the sector referenced by the AID to the MAD.

Parameters
aidThe application ID.
sectorThe sector.
madKeyAThe MAD key A for read access.
madKeyBThe MAD key B for write access.

◆ updateBinary()

virtual void logicalaccess::MifareCommands::updateBinary ( unsigned char  blockno,
const ByteVector buf 
)
pure virtual

Write bytes to the card.

Parameters
blocknoThe block number.
bufThe buffer containing the data.
buflenThe length of buffer.
Returns
The count of bytes written.

Implemented in logicalaccess::MifarePlusSL1Commands, logicalaccess::MifarePlusSL1Policy< MifareSL1Impl, MifareClassicImpl >, logicalaccess::MifareOK5553Commands, logicalaccess::MifarePCSCCommands, and logicalaccess::MifareSTidSTRCommands.

◆ writeSector()

void logicalaccess::MifareCommands::writeSector ( int  sector,
int  start_block,
const ByteVector buf,
std::shared_ptr< MifareKey keyA,
std::shared_ptr< MifareKey keyB,
const MifareAccessInfo::SectorAccessBits sab,
unsigned char  userbyte = 0x00,
MifareAccessInfo::SectorAccessBits newsab = nullptr,
std::shared_ptr< MifareKey newkeyA = std::shared_ptr<MifareKey>(),
std::shared_ptr< MifareKey newkeyB = std::shared_ptr<MifareKey>() 
)
finalvirtual

◆ writeSectors()

void logicalaccess::MifareCommands::writeSectors ( int  start_sector,
int  stop_sector,
int  start_block,
const ByteVector buf,
std::shared_ptr< MifareKey keyA,
std::shared_ptr< MifareKey keyB,
const MifareAccessInfo::SectorAccessBits sab,
unsigned char  userbyte = 0x00,
MifareAccessInfo::SectorAccessBits newsab = nullptr,
std::shared_ptr< MifareKey newkeyA = std::shared_ptr<MifareKey>(),
std::shared_ptr< MifareKey newkeyB = std::shared_ptr<MifareKey>() 
)
finalvirtual

◆ writeValueBlock()

bool logicalaccess::MifareCommands::writeValueBlock ( uint8_t  blockno,
int32_t  value,
uint8_t  backup_blockno 
)

Write a value block, using value as the numerical value to be written and backup_blockno as the address of the backup block.


The documentation for this class was generated from the following files: