5 #define DESFIRE(tag) ((struct desfire_tag *) tag)
6 #define DESFIRE_KEY(key) ((struct desfire_key *) key)
8 #define MAX_CRYPTO_BLOCK_SIZE 16
9 /* Mifare DESFire EV1 Application crypto operations */
10 #define APPLICATION_CRYPTO_DES 0x00
11 #define APPLICATION_CRYPTO_3K3DES 0x40
12 #define APPLICATION_CRYPTO_AES 0x80
20 } MifareCryptoDirection
;
25 } MifareCryptoOperation
;
27 #define MDCM_MASK 0x000F
31 // Data send to the PICC is used to update the CMAC
32 #define CMAC_COMMAND 0x010
33 // Data received from the PICC is used to update the CMAC
34 #define CMAC_VERIFY 0x020
36 // MAC the command (when MDCM_MACED)
37 #define MAC_COMMAND 0x100
38 // The command returns a MAC to verify (when MDCM_MACED)
39 #define MAC_VERIFY 0x200
41 #define ENC_COMMAND 0x1000
44 #define MAC_MASK 0x0F0
45 #define CMAC_MACK 0xF00
47 /* Communication mode */
48 #define MDCM_PLAIN 0x00
49 #define MDCM_MACED 0x01
50 #define MDCM_ENCIPHERED 0x03
52 /* Error code managed by the library */
53 #define CRYPTO_ERROR 0x01
56 enum DESFIRE_AUTH_SCHEME
{
61 enum DESFIRE_CRYPTOALGO
{
70 enum DESFIRE_CRYPTOALGO type
;
72 // DES_key_schedule ks1;
73 // DES_key_schedule ks2;
74 // DES_key_schedule ks3;
81 typedef struct desfire_key
*desfirekey_t
;
84 iso14a_card_select_t info
;
86 uint8_t last_picc_error
;
87 uint8_t last_internal_error
;
88 uint8_t last_pcd_error
;
89 desfirekey_t session_key
;
90 enum DESFIRE_AUTH_SCHEME authentication_scheme
;
91 uint8_t authenticated_key_no
;
93 uint8_t ivect
[MAX_CRYPTO_BLOCK_SIZE
];
95 uint8_t *crypto_buffer
;
96 size_t crypto_buffer_size
;
97 uint32_t selected_application
;
99 typedef struct desfire_tag
*desfiretag_t
;
103 enum DESFIRE_FILE_TYPES
{
104 MDFT_STANDARD_DATA_FILE
= 0x00,
105 MDFT_BACKUP_DATA_FILE
= 0x01,
106 MDFT_VALUE_FILE_WITH_BACKUP
= 0x02,
107 MDFT_LINEAR_RECORD_FILE_WITH_BACKUP
= 0x03,
108 MDFT_CYCLIC_RECORD_FILE_WITH_BACKUP
= 0x04
113 enum DESFIRE_STATUS
{
116 OUT_OF_EEPROM_ERROR
= 0x0e,
117 ILLEGAL_COMMAND_CODE
= 0x1c,
118 INTEGRITY_ERROR
= 0x1e,
121 PERMISSION_DENIED
= 0x9d,
122 PARAMETER_ERROR
= 0x9e,
123 APPLICATION_NOT_FOUND
= 0xa0,
124 APPL_INTEGRITY_ERROR
= 0xa1,
125 AUTHENTICATION_ERROR
= 0xae,
126 ADDITIONAL_FRAME
= 0xaf,
127 BOUNDARY_ERROR
= 0xbe,
128 PICC_INTEGRITY_ERROR
= 0xc1,
129 COMMAND_ABORTED
= 0xca,
130 PICC_DISABLED_ERROR
= 0xcd,
132 DUPLICATE_ERROR
= 0xde,
134 FILE_NOT_FOUND
= 0xf0,
135 FILE_INTEGRITY_ERROR
= 0xf1
139 CREATE_APPLICATION
= 0xca,
140 DELETE_APPLICATION
= 0xda,
141 GET_APPLICATION_IDS
= 0x6a,
142 SELECT_APPLICATION
= 0x5a,
150 LIMITED_CREDIT
= 0x1c,
153 CLEAR_RECORD_FILE
= 0xeb,
154 COMMIT_TRANSACTION
= 0xc7,
155 ABORT_TRANSACTION
= 0xa7,
156 GET_FREE_MEMORY
= 0x6e,
158 GET_FILE_SETTINGS
= 0xf5,
159 CHANGE_FILE_SETTINGS
= 0x5f,
160 CREATE_STD_DATA_FILE
= 0xcd,
161 CREATE_BACKUP_DATA_FILE
= 0xcb,
162 CREATE_VALUE_FILE
= 0xcc,
163 CREATE_LINEAR_RECORD_FILE
= 0xc1,
164 CREATE_CYCLIC_RECORD_FILE
= 0xc0,
166 AUTHENTICATE
= 0x0a, // AUTHENTICATE_NATIVE
167 AUTHENTICATE_ISO
= 0x1a, // AUTHENTICATE_STANDARD
168 AUTHENTICATE_AES
= 0xaa,
169 CHANGE_KEY_SETTINGS
= 0x54,
170 GET_KEY_SETTINGS
= 0x45,
172 GET_KEY_VERSION
= 0x64,
173 AUTHENTICATION_FRAME
= 0xAF