27 #ifndef __DESFIRE_EFFILE_H__ 28 #define __DESFIRE_EFFILE_H__ 30 #include "DESFireFirmwareSettings.h" 31 #include "DESFireInstructions.h" 33 #define EFFILE_DATA_CHUNK_SIZE (4) 34 #define EFFILE_DATA_CHUNK_ALIGNAT __attribute__((align(EFFILE_DATA_CHUNK_SIZE))) 37 #define ISO7816_4_CURRENT_EF_FILE_ID 0x0000 38 #define ISO7816_4_CURRENT_DF_FILE_ID 0x3FFF 39 #define ISO7816_4_MASTER_FILE_ID 0x3F00 44 #define DESFIRE_FILE_STANDARD_DATA 0 45 #define DESFIRE_FILE_BACKUP_DATA 1 46 #define DESFIRE_FILE_VALUE_DATA 2 47 #define DESFIRE_FILE_LINEAR_RECORDS 3 48 #define DESFIRE_FILE_CIRCULAR_RECORDS 4 50 #define DESFIRE_FILE_NOFILE_INDEX (0xff) 55 typedef struct DESFIRE_FIRMWARE_PACKING {
59 uint16_t FileDataAddress;
60 union DESFIRE_FIRMWARE_ALIGNAT {
61 struct DESFIRE_FIRMWARE_ALIGNAT {
64 struct DESFIRE_FIRMWARE_ALIGNAT {
68 struct DESFIRE_FIRMWARE_ALIGNAT {
73 uint8_t LimitedCreditEnabled;
74 int32_t PreviousDebit;
76 struct DESFIRE_FIRMWARE_ALIGNAT {
78 uint16_t RecordPointer;
80 uint8_t RecordSize[3];
81 uint8_t CurrentNumRecords[3];
82 uint8_t MaxRecordCount[3];
85 } DESFireFileTypeSettings;
87 uint16_t GetFileSizeFromFileType(DESFireFileTypeSettings *File);
89 typedef struct DESFIRE_FIRMWARE_PACKING {
91 DESFireFileTypeSettings File;
92 } SelectedFileCacheType;
98 uint16_t GetFileDataAreaBlockId(uint8_t FileIndex);
99 uint8_t ReadFileControlBlockIntoCacheStructure(uint8_t FileNum, SelectedFileCacheType *FileCache);
100 uint8_t ReadFileControlBlock(uint8_t FileNum, DESFireFileTypeSettings *File);
101 uint8_t WriteFileControlBlock(uint8_t FileNum, DESFireFileTypeSettings *File);
104 uint8_t CreateFileHeaderData(uint8_t FileNum, uint8_t CommSettings,
105 uint16_t AccessRights, DESFireFileTypeSettings *File);
106 uint8_t CreateStandardFile(uint8_t FileNum, uint8_t CommSettings, uint16_t AccessRights, uint16_t FileSize);
107 uint8_t CreateBackupFile(uint8_t FileNum, uint8_t CommSettings, uint16_t AccessRights, uint16_t FileSize);
108 uint8_t CreateValueFile(uint8_t FileNum, uint8_t CommSettings, uint16_t AccessRights,
109 int32_t LowerLimit, int32_t UpperLimit, int32_t Value,
bool LimitedCreditEnabled);
110 uint8_t CreateRecordFile(uint8_t FileType, uint8_t FileNum, uint8_t CommSettings, uint16_t AccessRights,
111 uint8_t *RecordSize, uint8_t *MaxRecordSize);
112 uint8_t DeleteFile(uint8_t FileIndex);
117 TransferStatus ReadDataFileTransfer(uint8_t *Buffer);
118 uint8_t WriteDataFileTransfer(uint8_t *Buffer, uint8_t ByteCount);
119 uint8_t ReadDataFileSetup(uint8_t FileIndex, uint8_t CommSettings, uint16_t Offset, uint16_t Length);
120 uint8_t WriteDataFileSetup(uint8_t FileIndex, uint8_t FileType, uint8_t CommSettings, uint16_t Offset, uint16_t Length);
121 uint16_t ReadDataFileIterator(uint8_t *Buffer);
122 uint8_t WriteDataFileInternal(uint8_t *Buffer, uint16_t ByteCount);
123 uint16_t WriteDataFileIterator(uint8_t *Buffer, uint16_t ByteCount);
126 #define DESFIRE_ACCESS_FREE 0xE 127 #define DESFIRE_ACCESS_DENY 0xF 130 #define VALIDATE_ACCESS_READWRITE ((uint16_t) (0x000f)) 131 #define VALIDATE_ACCESS_WRITE ((uint16_t) (0x000f << 4)) 132 #define VALIDATE_ACCESS_READ ((uint16_t) (0x000f << 8)) 133 #define VALIDATE_ACCESS_CHANGE ((uint16_t) (0x000f << 12)) 135 #define VALIDATED_ACCESS_DENIED 0 136 #define VALIDATED_ACCESS_GRANTED 1 137 #define VALIDATED_ACCESS_GRANTED_PLAINTEXT 2 143 #define GetReadPermissions(AccessRights) \ 144 (BYTE) (AccessRights & 0x000f) 145 #define GetWritePermissions(AccessRights) \ 146 (BYTE) (((0x00f0 & AccessRights) >> 4) & 0x000f) 147 #define GetReadWritePermissions(AccessRights) \ 148 (BYTE) (((0x0f00 & AccessRights) >> 8) & 0x000f) 149 #define GetChangePermissions(AccessRights) \ 150 (BYTE) (((0xf000 & AccessRights) >> 12) & 0x000f) 152 const char *GetFileAccessPermissionsDesc(uint16_t fileAccessRights);
160 uint8_t CreateFileCommonValidation(uint8_t FileNum);
161 uint8_t ValidateAuthentication(uint16_t AccessRights, uint16_t CheckMask);