7#ifndef LOGICALACCESS_DESFIRECOMMANDS_HPP
8#define LOGICALACCESS_DESFIRECOMMANDS_HPP
18#define EXCEPTION_MSG_SELECTAPPLICATION \
19 "Select application failed."
24#define DF_INS_AUTHENTICATE 0x0A
25#define DF_INS_CHANGE_KEY_SETTINGS 0x54
26#define DF_INS_GET_KEY_SETTINGS 0x45
27#define DF_INS_CHANGE_KEY 0xC4
28#define DF_INS_GET_KEY_VERSION 0x64
30#define DF_INS_CREATE_APPLICATION 0xCA
31#define DF_INS_DELETE_APPLICATION 0xDA
32#define DF_INS_GET_APPLICATION_IDS 0x6A
33#define DF_INS_SELECT_APPLICATION 0x5A
34#define DF_INS_FORMAT_PICC 0xFC
35#define DF_INS_GET_VERSION 0x60
37#define DF_INS_GET_FILE_IDS 0x6F
38#define DF_INS_GET_FILE_SETTINGS 0xF5
39#define DF_INS_CHANGE_FILE_SETTINGS 0x5F
40#define DF_INS_CREATE_STD_DATA_FILE 0xCD
41#define DF_INS_CREATE_BACKUP_DATA_FILE 0xCB
42#define DF_INS_CREATE_VALUE_FILE 0xCC
43#define DF_INS_CREATE_LINEAR_RECORD_FILE 0xC1
44#define DF_INS_CREATE_CYCLIC_RECORD_FILE 0xC0
45#define DF_INS_DELETE_FILE 0xDF
47#define DF_INS_READ_DATA 0xBD
48#define DF_INS_WRITE_DATA 0x3D
49#define DF_INS_GET_VALUE 0x6C
50#define DF_INS_CREDIT 0x0C
51#define DF_INS_DEBIT 0xDC
52#define DF_INS_LIMITED_CREDIT 0x1C
53#define DF_INS_WRITE_RECORD 0x3B
54#define DF_INS_READ_RECORDS 0xBB
55#define DF_INS_CLEAR_RECORD_FILE 0xEB
56#define DF_COMMIT_TRANSACTION 0xC7
57#define DF_INS_ABORT_TRANSACTION 0xA7
59#define DF_INS_ADDITIONAL_FRAME 0xAF
61#define DF_CLA_ISO_WRAP 0x90
64#define CMD_DESFIRE "DESFire"
161 unsigned char fileSize[3];
181 unsigned char recordSize[3];
182 unsigned char maxNumberRecords[3];
184 currentNumberRecords[3];
194 unsigned char accessRights[2];
229 unsigned char uid[7];
230 unsigned char batchNo[5];
239 virtual void selectApplication(std::shared_ptr<DESFireLocation> location);
247 virtual void createApplication(std::shared_ptr<DESFireLocation> location,
256 virtual void createStdDataFile(std::shared_ptr<DESFireLocation> location,
258 unsigned int fileSize);
267 virtual EncryptionMode getEncryptionMode(
unsigned char fileno,
bool isReadMode,
268 bool *needLoadKey =
nullptr);
272 bool *needLoadKey =
nullptr);
279 virtual unsigned int getFileLength(
unsigned char fileno);
295 unsigned char maxNbKeys) = 0;
314 virtual void changeKey(
unsigned char keyno, std::shared_ptr<DESFireKey> key) = 0;
322 unsigned char &maxNbKeys) = 0;
365 unsigned int fileSize) = 0;
376 unsigned int fileSize) = 0;
390 int32_t lowerLimit, int32_t upperLimit,
391 int32_t value,
bool limitedCreditEnabled) = 0;
403 unsigned int fileSize,
404 unsigned int maxNumberOfRecords) = 0;
416 unsigned int fileSize,
417 unsigned int maxNumberOfRecords) = 0;
443 virtual void writeData(
unsigned char fileno,
unsigned int offset,
460 virtual void credit(
unsigned char fileno,
unsigned int value,
487 virtual void writeRecord(
unsigned char fileno,
unsigned int offset,
528 virtual void authenticate(
unsigned char keyno, std::shared_ptr<DESFireKey> key) = 0;
LLA_CARDS_DESFIRE_API void getDESFireChip(std::shared_ptr< logicalaccess::Chip > *chip)
Definition: libraryentry.cpp:27
The base commands class for all card commands.
Definition: commands.hpp:21
The DESFire commands class.
Definition: desfirecommands.hpp:130
virtual SignatureResult IKS_getLastReadSignature() const
Definition: desfirecommands.hpp:543
virtual void abortTransaction()=0
Abort the transaction.
virtual void createLinearRecordFile(unsigned char fileno, EncryptionMode comSettings, const DESFireAccessRights &accessRights, unsigned int fileSize, unsigned int maxNumberOfRecords)=0
Create a new linear record file in the current application.
virtual void getKeySettings(DESFireKeySettings &settings, unsigned char &maxNbKeys)=0
Get key settings on the current application.
virtual void clearRecordFile(unsigned char fileno)=0
Clear a specific record file.
virtual void deleteFile(unsigned char fileno)=0
Delete a file in the current application.
virtual int32_t getValue(unsigned char fileno, EncryptionMode mode)=0
Get value from a specific value file.
virtual DESFireCardVersion getVersion()=0
Get the card version information.
virtual void writeData(unsigned char fileno, unsigned int offset, const ByteVector &data, EncryptionMode mode)=0
Write data into a specific file.
virtual void credit(unsigned char fileno, unsigned int value, EncryptionMode mode)=0
Credit a specific value file.
virtual void createBackupFile(unsigned char fileno, EncryptionMode comSettings, const DESFireAccessRights &accessRights, unsigned int fileSize)=0
Create a new backup file in the current application.
virtual void debit(unsigned char fileno, unsigned int value, EncryptionMode mode)=0
Debit a specific value file.
virtual void selectApplication(unsigned int aid)=0
Select an application.
virtual ByteVector readData(unsigned char fileno, unsigned int offset, unsigned int length, EncryptionMode mode)=0
Read data from a specific file.
virtual void changeKeySettings(DESFireKeySettings settings)=0
Change key settings for the current application.
DESFireCommands(std::string cmdtype)
Constructor.
Definition: desfirecommands.hpp:144
virtual void changeFileSettings(unsigned char fileno, EncryptionMode comSettings, const DESFireAccessRights &accessRights, bool plain)=0
Change file settings of a specific file in the current application.
virtual void createApplication(unsigned int aid, DESFireKeySettings settings, unsigned char maxNbKeys)=0
Create a new application.
virtual ByteVector readRecords(unsigned char fileno, unsigned int offset, unsigned int length, EncryptionMode mode)=0
Read record from a specific record file.
virtual void commitTransaction()=0
Commit the transaction.
virtual void erase()=0
Erase the card.
virtual void writeRecord(unsigned char fileno, unsigned int offset, const ByteVector &data, EncryptionMode mode)=0
Write record into a specific record file.
virtual void limitedCredit(unsigned char fileno, int32_t value, EncryptionMode mode)=0
Limit credit on a specific value file.
virtual ByteVector getFileIDs()=0
Get the File IDentifiers of all active files within the currently selected application.
virtual std::vector< unsigned int > getApplicationIDs()=0
Get the current application list.
virtual void authenticate(unsigned char keyno=0)=0
Authenticate a block, given a key number.
virtual void createValueFile(unsigned char fileno, EncryptionMode comSettings, const DESFireAccessRights &accessRights, int32_t lowerLimit, int32_t upperLimit, int32_t value, bool limitedCreditEnabled)=0
Create a new value file in the current application.
DESFireCommands()
Constructor.
Definition: desfirecommands.hpp:135
virtual void createStdDataFile(unsigned char fileno, EncryptionMode comSettings, const DESFireAccessRights &accessRights, unsigned int fileSize)=0
Create a new data file in the current application.
virtual FileSetting getFileSettings(unsigned char fileno)=0
Get settings of a specific file in the current application.
virtual void changeKey(unsigned char keyno, std::shared_ptr< DESFireKey > key)=0
Change a key in the current application.
virtual void authenticate(unsigned char keyno, std::shared_ptr< DESFireKey > key)=0
Authenticate a block, given a key number.
virtual void deleteApplication(unsigned int aid)=0
Delete an application.
virtual void createCyclicRecordFile(unsigned char fileno, EncryptionMode comSettings, const DESFireAccessRights &accessRights, unsigned int fileSize, unsigned int maxNumberOfRecords)=0
Create a new cyclic record file in the current application.
#define CMD_DESFIRE
Definition: desfirecommands.hpp:64
std::vector< uint8_t > ByteVector
Definition: lla_fwd.hpp:80
TaskAccessRights
The access key flag.
Definition: desfirecommands.hpp:83
@ AR_KEY11
Definition: desfirecommands.hpp:95
@ AR_KEY4
Definition: desfirecommands.hpp:88
@ AR_KEY13
Definition: desfirecommands.hpp:97
@ AR_KEY1
Definition: desfirecommands.hpp:85
@ AR_NEVER
Definition: desfirecommands.hpp:99
@ AR_FREE
Definition: desfirecommands.hpp:98
@ AR_KEY10
Definition: desfirecommands.hpp:94
@ AR_KEY5
Definition: desfirecommands.hpp:89
@ AR_KEY3
Definition: desfirecommands.hpp:87
@ AR_KEY0
Definition: desfirecommands.hpp:84
@ AR_KEY7
Definition: desfirecommands.hpp:91
@ AR_KEY9
Definition: desfirecommands.hpp:93
@ AR_KEY12
Definition: desfirecommands.hpp:96
@ AR_KEY6
Definition: desfirecommands.hpp:90
@ AR_KEY2
Definition: desfirecommands.hpp:86
@ AR_KEY8
Definition: desfirecommands.hpp:92
EncryptionMode
The file communication mode (or encryption mode)
Definition: desfirelocation.hpp:18
short AccessRightsInMemory(const DESFireAccessRights &rights)
Convert file access rights into flags.
Definition: desfirecommands.hpp:118
DESFireKeySettings
The key settings.
Definition: desfirecommands.hpp:69
@ KS_DEFAULT
Definition: desfirecommands.hpp:77
@ KS_CHANGE_KEY_FROZEN
Definition: desfirecommands.hpp:76
@ KS_ALLOW_CHANGE_MK
Definition: desfirecommands.hpp:70
@ KS_FREE_CREATE_DELETE_WITHOUT_MK
Definition: desfirecommands.hpp:72
@ KS_FREE_LISTING_WITHOUT_MK
Definition: desfirecommands.hpp:71
@ KS_CHANGE_KEY_WITH_TARGETED_KEYNO
Definition: desfirecommands.hpp:75
@ KS_CHANGE_KEY_WITH_MK
Definition: desfirecommands.hpp:74
@ KS_CONFIGURATION_CHANGEABLE
Definition: desfirecommands.hpp:73
Access rights on DESFire file.
Definition: desfirecommands.hpp:106
TaskAccessRights writeAccess
Write access.
Definition: desfirecommands.hpp:108
TaskAccessRights readAndWriteAccess
Read and Write access.
Definition: desfirecommands.hpp:109
TaskAccessRights readAccess
Read access.
Definition: desfirecommands.hpp:107
TaskAccessRights changeAccess
Change access.
Definition: desfirecommands.hpp:110
Card information about software and hardware version.
Definition: desfirecommands.hpp:212
unsigned char hardwareType
The hardware type.
Definition: desfirecommands.hpp:214
unsigned char softwareType
The software type.
Definition: desfirecommands.hpp:222
unsigned char softwareMnVersion
The software minor version.
Definition: desfirecommands.hpp:225
unsigned char softwareMjVersion
The software major version.
Definition: desfirecommands.hpp:224
unsigned char hardwareMjVersion
The hardware major version.
Definition: desfirecommands.hpp:216
unsigned char hardwareSubType
The hardware subtype.
Definition: desfirecommands.hpp:215
unsigned char softwareVendor
The software vendor.
Definition: desfirecommands.hpp:221
unsigned char cwProd
The production id.
Definition: desfirecommands.hpp:231
unsigned char softwareSubType
The software subtype.
Definition: desfirecommands.hpp:223
unsigned char hardwareStorageSize
The hardware storage size.
Definition: desfirecommands.hpp:218
unsigned char hardwareMnVersion
The hardware minor version.
Definition: desfirecommands.hpp:217
unsigned char hardwareProtocol
The hardware protocol.
Definition: desfirecommands.hpp:219
unsigned char yearProd
The production year.
Definition: desfirecommands.hpp:232
unsigned char hardwareVendor
The hardware vendor.
Definition: desfirecommands.hpp:213
unsigned char softwareProtocol
The software protocol.
Definition: desfirecommands.hpp:227
unsigned char softwareStorageSize
The software storage size.
Definition: desfirecommands.hpp:226
Describe setting for Data File type.
Definition: desfirecommands.hpp:160
Describe file setting.
Definition: desfirecommands.hpp:191
unsigned char comSett
The communication setting.
Definition: desfirecommands.hpp:193
ValueFileSetting valueFile
Definition: desfirecommands.hpp:197
unsigned char fileType
The file type.
Definition: desfirecommands.hpp:192
DataFileSetting dataFile
Definition: desfirecommands.hpp:196
RecordFileSetting recordFile
Definition: desfirecommands.hpp:198
Describe setting for Record File type.
Definition: desfirecommands.hpp:180
Describe setting for Value File type.
Definition: desfirecommands.hpp:168
int32_t upperLimit
The upper value limit.
Definition: desfirecommands.hpp:170
bool limitedCreditEnabled
True if limited credit is enabled, false otherwise.
Definition: desfirecommands.hpp:172
int32_t limitedCreditValue
The limited credit value.
Definition: desfirecommands.hpp:171
int32_t lowerLimit
The lower value limit.
Definition: desfirecommands.hpp:169
Definition: RemoteCrypto.hpp:9