27 #ifndef __DESFIRE_PICC_CONTROL_H__ 28 #define __DESFIRE_PICC_CONTROL_H__ 30 #include "../../Configuration.h" 32 #include "DESFireFirmwareSettings.h" 33 #include "DESFirePICCHeaderLayout.h" 34 #include "DESFireInstructions.h" 35 #include "DESFireApplicationDirectory.h" 36 #include "DESFireFile.h" 37 #include "DESFireCrypto.h" 44 extern DESFirePICCInfoType Picc;
45 extern DESFireAppDirType AppDir;
48 extern SelectedAppCacheType SelectedApp;
49 extern SelectedFileCacheType SelectedFile;
51 typedef void (*TransferSourceFuncType)(BYTE *Buffer, BYTE Count);
52 typedef void (*TransferSinkFuncType)(BYTE *Buffer, BYTE Count);
53 typedef void (*TransferChecksumUpdateFuncType)(
const BYTE *Buffer, BYTE Count);
54 typedef BYTE(*TransferChecksumFinalFuncType)(BYTE *Buffer);
55 typedef BYTE(*TransferEncryptFuncType)(BYTE *Buffer, BYTE Count);
56 typedef TransferStatus(*PiccToPcdTransferFilterFuncType)(BYTE *Buffer);
57 typedef BYTE(*PcdToPiccTransferFilterFuncType)(BYTE *Buffer, BYTE Count);
60 typedef union DESFIRE_FIRMWARE_PACKING {
61 struct DESFIRE_FIRMWARE_ALIGNAT {
64 BYTE BlockBuffer[CRYPTO_MAX_BLOCK_SIZE];
65 struct DESFIRE_FIRMWARE_ALIGNAT {
66 TransferChecksumUpdateFuncType UpdateFunc;
67 TransferChecksumFinalFuncType FinalFunc;
68 BYTE AvailablePlaintext;
69 struct DESFIRE_FIRMWARE_ALIGNAT {
70 union DESFIRE_FIRMWARE_ALIGNAT {
71 CryptoAESCBCFuncType AESFunc;
72 CryptoTDEACBCFuncType TDEAFunc;
77 BYTE CMAC[DESFIRE_CMAC_LENGTH];
81 struct DESFIRE_FIRMWARE_ALIGNAT {
83 struct DESFIRE_FIRMWARE_ALIGNAT {
84 TransferSourceFuncType Func;
87 struct DESFIRE_FIRMWARE_ALIGNAT {
88 BOOL FirstPaddingBitSet;
89 TransferEncryptFuncType Func;
90 BYTE AvailablePlaintext;
93 struct DESFIRE_FIRMWARE_ALIGNAT {
95 struct DESFIRE_FIRMWARE_ALIGNAT {
96 TransferSinkFuncType Func;
99 struct DESFIRE_FIRMWARE_ALIGNAT {
100 TransferEncryptFuncType Func;
101 BYTE AvailablePlaintext;
105 extern TransferStateType TransferState;
108 void SyncronizePICCInfo(
void);
109 TransferStatus PiccToPcdTransfer(uint8_t *Buffer);
110 uint8_t PcdToPiccTransfer(uint8_t *Buffer, uint8_t Count);
113 uint8_t ReadDataFilterSetup(uint8_t CommSettings);
114 uint8_t WriteDataFilterSetup(uint8_t CommSettings);
117 void InitialisePiccBackendEV0(uint8_t StorageSize);
118 void InitialisePiccBackendEV1(uint8_t StorageSize);
119 void ResetPiccBackend(
void);
120 bool IsEmulatingEV1(
void);
121 void GetPiccHardwareVersionInfo(uint8_t *Buffer);
122 void GetPiccSoftwareVersionInfo(uint8_t *Buffer);
123 void GetPiccManufactureInfo(uint8_t *Buffer);
124 uint8_t GetPiccKeySettings(
void);
125 void FormatPicc(
void);
126 void CreatePiccApp(
void);
127 void FactoryFormatPiccEV0(
void);
128 void FactoryFormatPiccEV1(uint8_t StorageSize);
129 void GetPiccUid(ConfigurationUidType Uid);
130 void SetPiccUid(ConfigurationUidType Uid);