Mercurial > code > home > repos > homeauto
comparison service/rfid_pn532_py/pyfreefare/freefare.h @ 403:b4404948d1e8
working on pyfreefare
Ignore-this: aaf74e9bbfeac1cafeff31cb2315b29a
author | drewp@bigasterisk.com |
---|---|
date | Mon, 04 Mar 2019 15:18:46 -0800 |
parents | 2e684f93ec25 |
children | 19ef0ac8f7f7 |
comparison
equal
deleted
inserted
replaced
402:2e684f93ec25 | 403:b4404948d1e8 |
---|---|
24 // MIFARE_PLUS_X4K, | 24 // MIFARE_PLUS_X4K, |
25 MIFARE_ULTRALIGHT, | 25 MIFARE_ULTRALIGHT, |
26 MIFARE_ULTRALIGHT_C, | 26 MIFARE_ULTRALIGHT_C, |
27 NTAG_21x, | 27 NTAG_21x, |
28 }; | 28 }; |
29 | 29 typedef enum freefare_tag_type freefare_tag_type; |
30 | |
30 struct freefare_tag; | 31 struct freefare_tag; |
31 typedef struct freefare_tag *FreefareTag; | 32 typedef struct freefare_tag *FreefareTag; |
32 | 33 |
33 /* Replace any MifareTag by the generic FreefareTag. */ | 34 /* Replace any MifareTag by the generic FreefareTag. */ |
34 typedef struct freefare_tag *MifareTag; | 35 typedef struct freefare_tag *MifareTag; |
42 typedef uint8_t MifareUltralightPageNumber; | 43 typedef uint8_t MifareUltralightPageNumber; |
43 typedef unsigned char MifareUltralightPage[4]; | 44 typedef unsigned char MifareUltralightPage[4]; |
44 | 45 |
45 FreefareTag *freefare_get_tags(nfc_device *device); | 46 FreefareTag *freefare_get_tags(nfc_device *device); |
46 FreefareTag freefare_tag_new(nfc_device *device, nfc_target target); | 47 FreefareTag freefare_tag_new(nfc_device *device, nfc_target target); |
47 enum freefare_tag_type freefare_get_tag_type(FreefareTag tag); | 48 freefare_tag_type freefare_get_tag_type(FreefareTag tag); |
48 const char *freefare_get_tag_friendly_name(FreefareTag tag); | 49 // const char *freefare_get_tag_friendly_name(FreefareTag tag); |
49 char *freefare_get_tag_uid(FreefareTag tag); | 50 // char *freefare_get_tag_uid(FreefareTag tag); |
50 void freefare_free_tag(FreefareTag tag); | 51 // void freefare_free_tag(FreefareTag tag); |
51 void freefare_free_tags(FreefareTag *tags); | 52 // void freefare_free_tags(FreefareTag *tags); |
52 bool freefare_selected_tag_is_present(nfc_device *device); | 53 // bool freefare_selected_tag_is_present(nfc_device *device); |
53 | 54 // |
54 const char *freefare_strerror(FreefareTag tag); | 55 // const char *freefare_strerror(FreefareTag tag); |
55 int freefare_strerror_r(FreefareTag tag, char *buffer, size_t len); | 56 // int freefare_strerror_r(FreefareTag tag, char *buffer, size_t len); |
56 void freefare_perror(FreefareTag tag, const char *string); | 57 // void freefare_perror(FreefareTag tag, const char *string); |
57 | 58 // |
58 | 59 // |
59 | 60 // |
60 bool felica_taste(nfc_device *device, nfc_target target); | 61 // bool felica_taste(nfc_device *device, nfc_target target); |
61 | 62 // |
62 #define FELICA_SC_RW 0x0009 | 63 // #define FELICA_SC_RW 0x0009 |
63 #define FELICA_SC_RO 0x000b | 64 // #define FELICA_SC_RO 0x000b |
64 | 65 // |
65 FreefareTag felica_tag_new(nfc_device *device, nfc_target target); | 66 // FreefareTag felica_tag_new(nfc_device *device, nfc_target target); |
66 void felica_tag_free(FreefareTag tag); | 67 // void felica_tag_free(FreefareTag tag); |
67 | 68 // |
68 ssize_t felica_read(FreefareTag tag, uint16_t service, uint8_t block, uint8_t *data, size_t length); | 69 // ssize_t felica_read(FreefareTag tag, uint16_t service, uint8_t block, uint8_t *data, size_t length); |
69 ssize_t felica_read_ex(FreefareTag tag, uint16_t service, uint8_t block_count, uint8_t blocks[], uint8_t *data, size_t length); | 70 // ssize_t felica_read_ex(FreefareTag tag, uint16_t service, uint8_t block_count, uint8_t blocks[], uint8_t *data, size_t length); |
70 ssize_t felica_write(FreefareTag tag, uint16_t service, uint8_t block, uint8_t *data, size_t length); | 71 // ssize_t felica_write(FreefareTag tag, uint16_t service, uint8_t block, uint8_t *data, size_t length); |
71 ssize_t felica_write_ex(FreefareTag tag, uint16_t service, uint8_t block_count, uint8_t blocks[], uint8_t *data, size_t length); | 72 // ssize_t felica_write_ex(FreefareTag tag, uint16_t service, uint8_t block_count, uint8_t blocks[], uint8_t *data, size_t length); |
72 | 73 // |
73 | 74 // |
74 | 75 // |
75 bool mifare_ultralight_taste(nfc_device *device, nfc_target target); | 76 // bool mifare_ultralight_taste(nfc_device *device, nfc_target target); |
76 bool mifare_ultralightc_taste(nfc_device *device, nfc_target target); | 77 // bool mifare_ultralightc_taste(nfc_device *device, nfc_target target); |
77 FreefareTag mifare_ultralight_tag_new(nfc_device *device, nfc_target target); | 78 // FreefareTag mifare_ultralight_tag_new(nfc_device *device, nfc_target target); |
78 FreefareTag mifare_ultralightc_tag_new(nfc_device *device, nfc_target target); | 79 // FreefareTag mifare_ultralightc_tag_new(nfc_device *device, nfc_target target); |
79 void mifare_ultralight_tag_free(FreefareTag tag); | 80 // void mifare_ultralight_tag_free(FreefareTag tag); |
80 void mifare_ultralightc_tag_free(FreefareTag tag); | 81 // void mifare_ultralightc_tag_free(FreefareTag tag); |
81 | 82 // |
82 int mifare_ultralight_connect(FreefareTag tag); | 83 // int mifare_ultralight_connect(FreefareTag tag); |
83 int mifare_ultralight_disconnect(FreefareTag tag); | 84 // int mifare_ultralight_disconnect(FreefareTag tag); |
84 | 85 // |
85 int mifare_ultralight_read(FreefareTag tag, const MifareUltralightPageNumber page, MifareUltralightPage *data); | 86 // int mifare_ultralight_read(FreefareTag tag, const MifareUltralightPageNumber page, MifareUltralightPage *data); |
86 int mifare_ultralight_write(FreefareTag tag, const MifareUltralightPageNumber page, const MifareUltralightPage data); | 87 // int mifare_ultralight_write(FreefareTag tag, const MifareUltralightPageNumber page, const MifareUltralightPage data); |
87 | 88 // |
88 int mifare_ultralightc_authenticate(FreefareTag tag, const MifareDESFireKey key); | 89 // int mifare_ultralightc_authenticate(FreefareTag tag, const MifareDESFireKey key); |
89 int mifare_ultralightc_set_key(FreefareTag tag, MifareDESFireKey key); | 90 // int mifare_ultralightc_set_key(FreefareTag tag, MifareDESFireKey key); |
90 bool is_mifare_ultralight(FreefareTag tag); | 91 // bool is_mifare_ultralight(FreefareTag tag); |
91 bool is_mifare_ultralightc(FreefareTag tag); | 92 // bool is_mifare_ultralightc(FreefareTag tag); |
92 bool is_mifare_ultralightc_on_reader(nfc_device *device, nfc_iso14443a_info nai); | 93 // bool is_mifare_ultralightc_on_reader(nfc_device *device, nfc_iso14443a_info nai); |
93 | 94 // |
94 | 95 // |
95 | 96 // |
96 bool ntag21x_taste(nfc_device *device, nfc_target target); | 97 // bool ntag21x_taste(nfc_device *device, nfc_target target); |
97 uint8_t ntag21x_last_error(FreefareTag tag); | 98 // uint8_t ntag21x_last_error(FreefareTag tag); |
98 | 99 // |
99 /* NTAG21x access features */ | 100 // /* NTAG21x access features */ |
100 #define NTAG_PROT 0x80 | 101 // #define NTAG_PROT 0x80 |
101 #define NTAG_CFGLCK 0x40 | 102 // #define NTAG_CFGLCK 0x40 |
102 #define NTAG_NFC_CNT_EN 0x20 | 103 // #define NTAG_NFC_CNT_EN 0x20 |
103 #define NTAG_NFC_CNT_PWD_PROT 0x10 | 104 // #define NTAG_NFC_CNT_PWD_PROT 0x10 |
104 #define NTAG_AUTHLIM 0x07 | 105 // #define NTAG_AUTHLIM 0x07 |
105 | 106 // |
106 enum ntag_tag_subtype { | 107 // enum ntag_tag_subtype { |
107 NTAG_UNKNOWN, | 108 // NTAG_UNKNOWN, |
108 NTAG_213, | 109 // NTAG_213, |
109 NTAG_215, | 110 // NTAG_215, |
110 NTAG_216 | 111 // NTAG_216 |
111 }; | 112 // }; |
112 | 113 // |
113 FreefareTag ntag21x_tag_new(nfc_device *device, nfc_target target); | 114 // FreefareTag ntag21x_tag_new(nfc_device *device, nfc_target target); |
114 FreefareTag ntag21x_tag_reuse(FreefareTag tag); /* Copy data from Ultralight tag to new NTAG21x, don't forget to free your old tag */ | 115 // FreefareTag ntag21x_tag_reuse(FreefareTag tag); /* Copy data from Ultralight tag to new NTAG21x, don't forget to free your old tag */ |
115 NTAG21xKey ntag21x_key_new(const uint8_t data[4], const uint8_t pack[2]); /* Create new key */ | 116 // NTAG21xKey ntag21x_key_new(const uint8_t data[4], const uint8_t pack[2]); /* Create new key */ |
116 void ntag21x_key_free(NTAG21xKey key); /* Clear key from memory */ | 117 // void ntag21x_key_free(NTAG21xKey key); /* Clear key from memory */ |
117 void ntag21x_tag_free(FreefareTag tag); | 118 // void ntag21x_tag_free(FreefareTag tag); |
118 int ntag21x_connect(FreefareTag tag); | 119 // int ntag21x_connect(FreefareTag tag); |
119 int ntag21x_disconnect(FreefareTag tag); | 120 // int ntag21x_disconnect(FreefareTag tag); |
120 int ntag21x_get_info(FreefareTag tag); /* Get all information about tag (size,vendor ...) */ | 121 // int ntag21x_get_info(FreefareTag tag); /* Get all information about tag (size,vendor ...) */ |
121 enum ntag_tag_subtype ntag21x_get_subtype(FreefareTag tag); /* Get subtype of tag */ | 122 // enum ntag_tag_subtype ntag21x_get_subtype(FreefareTag tag); /* Get subtype of tag */ |
122 uint8_t ntag21x_get_last_page(FreefareTag tag); /* Get last page address based on gathered info from function above */ | 123 // uint8_t ntag21x_get_last_page(FreefareTag tag); /* Get last page address based on gathered info from function above */ |
123 int ntag21x_read_signature(FreefareTag tag, uint8_t *data); /* Get tag signature */ | 124 // int ntag21x_read_signature(FreefareTag tag, uint8_t *data); /* Get tag signature */ |
124 int ntag21x_set_pwd(FreefareTag tag, uint8_t data[4]); /* Set password */ | 125 // int ntag21x_set_pwd(FreefareTag tag, uint8_t data[4]); /* Set password */ |
125 int ntag21x_set_pack(FreefareTag tag, uint8_t data[2]); /* Set pack */ | 126 // int ntag21x_set_pack(FreefareTag tag, uint8_t data[2]); /* Set pack */ |
126 int ntag21x_set_key(FreefareTag tag, const NTAG21xKey key); /* Set key */ | 127 // int ntag21x_set_key(FreefareTag tag, const NTAG21xKey key); /* Set key */ |
127 int ntag21x_set_auth(FreefareTag tag, uint8_t byte); /* Set AUTH0 byte (from which page starts password protection) */ | 128 // int ntag21x_set_auth(FreefareTag tag, uint8_t byte); /* Set AUTH0 byte (from which page starts password protection) */ |
128 int ntag21x_get_auth(FreefareTag tag, uint8_t *byte); /* Get AUTH0 byte */ | 129 // int ntag21x_get_auth(FreefareTag tag, uint8_t *byte); /* Get AUTH0 byte */ |
129 int ntag21x_access_enable(FreefareTag tag, uint8_t byte); /* Enable access feature in ACCESS byte */ | 130 // int ntag21x_access_enable(FreefareTag tag, uint8_t byte); /* Enable access feature in ACCESS byte */ |
130 int ntag21x_access_disable(FreefareTag tag, uint8_t byte); /* Disable access feature in ACCESS byte */ | 131 // int ntag21x_access_disable(FreefareTag tag, uint8_t byte); /* Disable access feature in ACCESS byte */ |
131 int ntag21x_get_access(FreefareTag tag, uint8_t *byte); /* Get ACCESS byte */ | 132 // int ntag21x_get_access(FreefareTag tag, uint8_t *byte); /* Get ACCESS byte */ |
132 int ntag21x_check_access(FreefareTag tag, uint8_t byte, bool *result); /* Check if access feature is enabled */ | 133 // int ntag21x_check_access(FreefareTag tag, uint8_t byte, bool *result); /* Check if access feature is enabled */ |
133 int ntag21x_get_authentication_limit(FreefareTag tag, uint8_t *byte); /* Get authentication limit */ | 134 // int ntag21x_get_authentication_limit(FreefareTag tag, uint8_t *byte); /* Get authentication limit */ |
134 int ntag21x_set_authentication_limit(FreefareTag tag, uint8_t byte); /* Set authentication limit (0x00 = disabled, [0x01,0x07] = valid range, > 0x07 invalid range) */ | 135 // int ntag21x_set_authentication_limit(FreefareTag tag, uint8_t byte); /* Set authentication limit (0x00 = disabled, [0x01,0x07] = valid range, > 0x07 invalid range) */ |
135 int ntag21x_read(FreefareTag tag, uint8_t page, uint8_t *data); /* Read 16 bytes starting from page */ | 136 // int ntag21x_read(FreefareTag tag, uint8_t page, uint8_t *data); /* Read 16 bytes starting from page */ |
136 int ntag21x_read4(FreefareTag tag, uint8_t page, uint8_t *data); /* Read 4 bytes on page */ | 137 // int ntag21x_read4(FreefareTag tag, uint8_t page, uint8_t *data); /* Read 4 bytes on page */ |
137 int ntag21x_fast_read(FreefareTag tag, uint8_t start_page, uint8_t end_page, uint8_t *data); /* Read n*4 bytes from range [start_page,end_page] */ | 138 // int ntag21x_fast_read(FreefareTag tag, uint8_t start_page, uint8_t end_page, uint8_t *data); /* Read n*4 bytes from range [start_page,end_page] */ |
138 int ntag21x_fast_read4(FreefareTag tag, uint8_t page, uint8_t *data); /* Fast read certain page */ | 139 // int ntag21x_fast_read4(FreefareTag tag, uint8_t page, uint8_t *data); /* Fast read certain page */ |
139 int ntag21x_read_cnt(FreefareTag tag, uint8_t *data); /* Read 3-byte NFC counter if enabled else it returns error */ | 140 // int ntag21x_read_cnt(FreefareTag tag, uint8_t *data); /* Read 3-byte NFC counter if enabled else it returns error */ |
140 int ntag21x_write(FreefareTag tag, uint8_t page, uint8_t data[4]); /* Write 4 bytes to page */ | 141 // int ntag21x_write(FreefareTag tag, uint8_t page, uint8_t data[4]); /* Write 4 bytes to page */ |
141 int ntag21x_compatibility_write(FreefareTag tag, uint8_t page, uint8_t data[4]); /* Writes 4 bytes to page with mifare classic write */ | 142 // int ntag21x_compatibility_write(FreefareTag tag, uint8_t page, uint8_t data[4]); /* Writes 4 bytes to page with mifare classic write */ |
142 int ntag21x_authenticate(FreefareTag tag, const NTAG21xKey key); /* Authenticate with tag */ | 143 // int ntag21x_authenticate(FreefareTag tag, const NTAG21xKey key); /* Authenticate with tag */ |
143 bool is_ntag21x(FreefareTag tag); /* Check if tag type is NTAG21x */ | 144 // bool is_ntag21x(FreefareTag tag); /* Check if tag type is NTAG21x */ |
144 bool ntag21x_is_auth_supported(nfc_device *device, nfc_iso14443a_info nai); /* Check if tag supports 21x commands */ | 145 // bool ntag21x_is_auth_supported(nfc_device *device, nfc_iso14443a_info nai); /* Check if tag supports 21x commands */ |
145 | 146 // |
146 | 147 // |
147 | 148 // |
148 bool mifare_mini_taste(nfc_device *device, nfc_target target); | 149 // bool mifare_mini_taste(nfc_device *device, nfc_target target); |
149 bool mifare_classic1k_taste(nfc_device *device, nfc_target target); | 150 // bool mifare_classic1k_taste(nfc_device *device, nfc_target target); |
150 bool mifare_classic4k_taste(nfc_device *device, nfc_target target); | 151 // bool mifare_classic4k_taste(nfc_device *device, nfc_target target); |
151 FreefareTag mifare_mini_tag_new(nfc_device *device, nfc_target target); | 152 // FreefareTag mifare_mini_tag_new(nfc_device *device, nfc_target target); |
152 FreefareTag mifare_classic1k_tag_new(nfc_device *device, nfc_target target); | 153 // FreefareTag mifare_classic1k_tag_new(nfc_device *device, nfc_target target); |
153 FreefareTag mifare_classic4k_tag_new(nfc_device *device, nfc_target target); | 154 // FreefareTag mifare_classic4k_tag_new(nfc_device *device, nfc_target target); |
154 void mifare_classic_tag_free(FreefareTag tag); | 155 // void mifare_classic_tag_free(FreefareTag tag); |
155 | 156 // |
156 typedef unsigned char MifareClassicBlock[16]; | 157 // typedef unsigned char MifareClassicBlock[16]; |
157 | 158 // |
158 typedef uint8_t MifareClassicSectorNumber; | 159 // typedef uint8_t MifareClassicSectorNumber; |
159 typedef unsigned char MifareClassicBlockNumber; | 160 // typedef unsigned char MifareClassicBlockNumber; |
160 | 161 // |
161 typedef enum { MFC_KEY_A, MFC_KEY_B } MifareClassicKeyType; | 162 // typedef enum { MFC_KEY_A, MFC_KEY_B } MifareClassicKeyType; |
162 typedef unsigned char MifareClassicKey[6]; | 163 // typedef unsigned char MifareClassicKey[6]; |
163 | 164 // |
164 /* NFC Forum public key */ | 165 // /* NFC Forum public key */ |
165 extern const MifareClassicKey mifare_classic_nfcforum_public_key_a; | 166 // extern const MifareClassicKey mifare_classic_nfcforum_public_key_a; |
166 | 167 // |
167 int mifare_classic_connect(FreefareTag tag); | 168 // int mifare_classic_connect(FreefareTag tag); |
168 int mifare_classic_disconnect(FreefareTag tag); | 169 // int mifare_classic_disconnect(FreefareTag tag); |
169 | 170 // |
170 int mifare_classic_authenticate(FreefareTag tag, const MifareClassicBlockNumber block, const MifareClassicKey key, const MifareClassicKeyType key_type); | 171 // int mifare_classic_authenticate(FreefareTag tag, const MifareClassicBlockNumber block, const MifareClassicKey key, const MifareClassicKeyType key_type); |
171 int mifare_classic_read(FreefareTag tag, const MifareClassicBlockNumber block, MifareClassicBlock *data); | 172 // int mifare_classic_read(FreefareTag tag, const MifareClassicBlockNumber block, MifareClassicBlock *data); |
172 int mifare_classic_init_value(FreefareTag tag, const MifareClassicBlockNumber block, const int32_t value, const MifareClassicBlockNumber adr); | 173 // int mifare_classic_init_value(FreefareTag tag, const MifareClassicBlockNumber block, const int32_t value, const MifareClassicBlockNumber adr); |
173 int mifare_classic_read_value(FreefareTag tag, const MifareClassicBlockNumber block, int32_t *value, MifareClassicBlockNumber *adr); | 174 // int mifare_classic_read_value(FreefareTag tag, const MifareClassicBlockNumber block, int32_t *value, MifareClassicBlockNumber *adr); |
174 int mifare_classic_write(FreefareTag tag, const MifareClassicBlockNumber block, const MifareClassicBlock data); | 175 // int mifare_classic_write(FreefareTag tag, const MifareClassicBlockNumber block, const MifareClassicBlock data); |
175 | 176 // |
176 int mifare_classic_increment(FreefareTag tag, const MifareClassicBlockNumber block, const uint32_t amount); | 177 // int mifare_classic_increment(FreefareTag tag, const MifareClassicBlockNumber block, const uint32_t amount); |
177 int mifare_classic_decrement(FreefareTag tag, const MifareClassicBlockNumber block, const uint32_t amount); | 178 // int mifare_classic_decrement(FreefareTag tag, const MifareClassicBlockNumber block, const uint32_t amount); |
178 int mifare_classic_restore(FreefareTag tag, const MifareClassicBlockNumber block); | 179 // int mifare_classic_restore(FreefareTag tag, const MifareClassicBlockNumber block); |
179 int mifare_classic_transfer(FreefareTag tag, const MifareClassicBlockNumber block); | 180 // int mifare_classic_transfer(FreefareTag tag, const MifareClassicBlockNumber block); |
180 | 181 // |
181 int mifare_classic_get_trailer_block_permission(FreefareTag tag, const MifareClassicBlockNumber block, const uint16_t permission, const MifareClassicKeyType key_type); | 182 // int mifare_classic_get_trailer_block_permission(FreefareTag tag, const MifareClassicBlockNumber block, const uint16_t permission, const MifareClassicKeyType key_type); |
182 int mifare_classic_get_data_block_permission(FreefareTag tag, const MifareClassicBlockNumber block, const unsigned char permission, const MifareClassicKeyType key_type); | 183 // int mifare_classic_get_data_block_permission(FreefareTag tag, const MifareClassicBlockNumber block, const unsigned char permission, const MifareClassicKeyType key_type); |
183 | 184 // |
184 int mifare_classic_format_sector(FreefareTag tag, const MifareClassicSectorNumber sector); | 185 // int mifare_classic_format_sector(FreefareTag tag, const MifareClassicSectorNumber sector); |
185 | 186 // |
186 void mifare_classic_trailer_block(MifareClassicBlock *block, const MifareClassicKey key_a, uint8_t ab_0, uint8_t ab_1, uint8_t ab_2, uint8_t ab_tb, const uint8_t gpb, const MifareClassicKey key_b); | 187 // void mifare_classic_trailer_block(MifareClassicBlock *block, const MifareClassicKey key_a, uint8_t ab_0, uint8_t ab_1, uint8_t ab_2, uint8_t ab_tb, const uint8_t gpb, const MifareClassicKey key_b); |
187 | 188 // |
188 MifareClassicSectorNumber mifare_classic_block_sector(MifareClassicBlockNumber block); | 189 // MifareClassicSectorNumber mifare_classic_block_sector(MifareClassicBlockNumber block); |
189 MifareClassicBlockNumber mifare_classic_sector_first_block(MifareClassicSectorNumber sector); | 190 // MifareClassicBlockNumber mifare_classic_sector_first_block(MifareClassicSectorNumber sector); |
190 size_t mifare_classic_sector_block_count(MifareClassicSectorNumber sector); | 191 // size_t mifare_classic_sector_block_count(MifareClassicSectorNumber sector); |
191 MifareClassicBlockNumber mifare_classic_sector_last_block(MifareClassicSectorNumber sector); | 192 // MifareClassicBlockNumber mifare_classic_sector_last_block(MifareClassicSectorNumber sector); |
192 | 193 // |
193 #define C_000 0 | 194 // #define C_000 0 |
194 #define C_001 1 | 195 // #define C_001 1 |
195 #define C_010 2 | 196 // #define C_010 2 |
196 #define C_011 3 | 197 // #define C_011 3 |
197 #define C_100 4 | 198 // #define C_100 4 |
198 #define C_101 5 | 199 // #define C_101 5 |
199 #define C_110 6 | 200 // #define C_110 6 |
200 #define C_111 7 | 201 // #define C_111 7 |
201 #define C_DEFAULT 255 | 202 // #define C_DEFAULT 255 |
202 | 203 // |
203 /* MIFARE Classic Access Bits */ | 204 // /* MIFARE Classic Access Bits */ |
204 #define MCAB_R 0x8 | 205 // #define MCAB_R 0x8 |
205 #define MCAB_W 0x4 | 206 // #define MCAB_W 0x4 |
206 #define MCAB_D 0x2 | 207 // #define MCAB_D 0x2 |
207 #define MCAB_I 0x1 | 208 // #define MCAB_I 0x1 |
208 | 209 // |
209 #define MCAB_READ_KEYA 0x400 | 210 // #define MCAB_READ_KEYA 0x400 |
210 #define MCAB_WRITE_KEYA 0x100 | 211 // #define MCAB_WRITE_KEYA 0x100 |
211 #define MCAB_READ_ACCESS_BITS 0x040 | 212 // #define MCAB_READ_ACCESS_BITS 0x040 |
212 #define MCAB_WRITE_ACCESS_BITS 0x010 | 213 // #define MCAB_WRITE_ACCESS_BITS 0x010 |
213 #define MCAB_READ_KEYB 0x004 | 214 // #define MCAB_READ_KEYB 0x004 |
214 #define MCAB_WRITE_KEYB 0x001 | 215 // #define MCAB_WRITE_KEYB 0x001 |
215 | 216 // |
216 struct mad_aid { | 217 // struct mad_aid { |
217 uint8_t application_code; | 218 // uint8_t application_code; |
218 uint8_t function_cluster_code; | 219 // uint8_t function_cluster_code; |
219 }; | 220 // }; |
220 typedef struct mad_aid MadAid; | 221 // typedef struct mad_aid MadAid; |
221 | 222 // |
222 struct mad; | 223 // struct mad; |
223 typedef struct mad *Mad; | 224 // typedef struct mad *Mad; |
224 | 225 // |
225 /* MAD Public read key A */ | 226 // /* MAD Public read key A */ |
226 extern const MifareClassicKey mad_public_key_a; | 227 // extern const MifareClassicKey mad_public_key_a; |
227 | 228 // |
228 /* AID - Adminisration codes */ | 229 // /* AID - Adminisration codes */ |
229 extern const MadAid mad_free_aid; | 230 // extern const MadAid mad_free_aid; |
230 extern const MadAid mad_defect_aid; | 231 // extern const MadAid mad_defect_aid; |
231 extern const MadAid mad_reserved_aid; | 232 // extern const MadAid mad_reserved_aid; |
232 extern const MadAid mad_card_holder_aid; | 233 // extern const MadAid mad_card_holder_aid; |
233 extern const MadAid mad_not_applicable_aid; | 234 // extern const MadAid mad_not_applicable_aid; |
234 | 235 // |
235 /* NFC Forum AID */ | 236 // /* NFC Forum AID */ |
236 extern const MadAid mad_nfcforum_aid; | 237 // extern const MadAid mad_nfcforum_aid; |
237 | 238 // |
238 Mad mad_new(const uint8_t version); | 239 // Mad mad_new(const uint8_t version); |
239 Mad mad_read(FreefareTag tag); | 240 // Mad mad_read(FreefareTag tag); |
240 int mad_write(FreefareTag tag, Mad mad, const MifareClassicKey key_b_sector_00, const MifareClassicKey key_b_sector_10); | 241 // int mad_write(FreefareTag tag, Mad mad, const MifareClassicKey key_b_sector_00, const MifareClassicKey key_b_sector_10); |
241 int mad_get_version(Mad mad); | 242 // int mad_get_version(Mad mad); |
242 void mad_set_version(Mad mad, const uint8_t version); | 243 // void mad_set_version(Mad mad, const uint8_t version); |
243 MifareClassicSectorNumber mad_get_card_publisher_sector(Mad mad); | 244 // MifareClassicSectorNumber mad_get_card_publisher_sector(Mad mad); |
244 int mad_set_card_publisher_sector(Mad mad, const MifareClassicSectorNumber cps); | 245 // int mad_set_card_publisher_sector(Mad mad, const MifareClassicSectorNumber cps); |
245 int mad_get_aid(Mad mad, const MifareClassicSectorNumber sector, MadAid *aid); | 246 // int mad_get_aid(Mad mad, const MifareClassicSectorNumber sector, MadAid *aid); |
246 int mad_set_aid(Mad mad, const MifareClassicSectorNumber sector, MadAid aid); | 247 // int mad_set_aid(Mad mad, const MifareClassicSectorNumber sector, MadAid aid); |
247 bool mad_sector_reserved(const MifareClassicSectorNumber sector); | 248 // bool mad_sector_reserved(const MifareClassicSectorNumber sector); |
248 void mad_free(Mad mad); | 249 // void mad_free(Mad mad); |
249 | 250 // |
250 MifareClassicSectorNumber *mifare_application_alloc(Mad mad, const MadAid aid, const size_t size); | 251 // MifareClassicSectorNumber *mifare_application_alloc(Mad mad, const MadAid aid, const size_t size); |
251 ssize_t mifare_application_read(FreefareTag tag, Mad mad, const MadAid aid, void *buf, size_t nbytes, const MifareClassicKey key, const MifareClassicKeyType key_type); | 252 // ssize_t mifare_application_read(FreefareTag tag, Mad mad, const MadAid aid, void *buf, size_t nbytes, const MifareClassicKey key, const MifareClassicKeyType key_type); |
252 ssize_t mifare_application_write(FreefareTag tag, Mad mad, const MadAid aid, const void *buf, size_t nbytes, const MifareClassicKey key, const MifareClassicKeyType key_type); | 253 // ssize_t mifare_application_write(FreefareTag tag, Mad mad, const MadAid aid, const void *buf, size_t nbytes, const MifareClassicKey key, const MifareClassicKeyType key_type); |
253 int mifare_application_free(Mad mad, const MadAid aid); | 254 // int mifare_application_free(Mad mad, const MadAid aid); |
254 | 255 // |
255 MifareClassicSectorNumber *mifare_application_find(Mad mad, const MadAid aid); | 256 // MifareClassicSectorNumber *mifare_application_find(Mad mad, const MadAid aid); |
256 | 257 // |
257 | 258 // |
258 | 259 // |
259 bool mifare_desfire_taste(nfc_device *device, nfc_target target); | 260 // bool mifare_desfire_taste(nfc_device *device, nfc_target target); |
260 | 261 // |
261 /* File types */ | 262 // /* File types */ |
262 | 263 // |
263 enum mifare_desfire_file_types { | 264 // enum mifare_desfire_file_types { |
264 MDFT_STANDARD_DATA_FILE = 0x00, | 265 // MDFT_STANDARD_DATA_FILE = 0x00, |
265 MDFT_BACKUP_DATA_FILE = 0x01, | 266 // MDFT_BACKUP_DATA_FILE = 0x01, |
266 MDFT_VALUE_FILE_WITH_BACKUP = 0x02, | 267 // MDFT_VALUE_FILE_WITH_BACKUP = 0x02, |
267 MDFT_LINEAR_RECORD_FILE_WITH_BACKUP = 0x03, | 268 // MDFT_LINEAR_RECORD_FILE_WITH_BACKUP = 0x03, |
268 MDFT_CYCLIC_RECORD_FILE_WITH_BACKUP = 0x04 | 269 // MDFT_CYCLIC_RECORD_FILE_WITH_BACKUP = 0x04 |
269 }; | 270 // }; |
270 | 271 // |
271 /* Communication mode */ | 272 // /* Communication mode */ |
272 | 273 // |
273 #define MDCM_PLAIN 0x00 | 274 // #define MDCM_PLAIN 0x00 |
274 #define MDCM_MACED 0x01 | 275 // #define MDCM_MACED 0x01 |
275 #define MDCM_ENCIPHERED 0x03 | 276 // #define MDCM_ENCIPHERED 0x03 |
276 | 277 // |
277 /* Mifare DESFire master key settings | 278 // /* Mifare DESFire master key settings |
278 bit 7 - 4: Always 0. | 279 // bit 7 - 4: Always 0. |
279 bit 3: PICC master key settings frozen = 0 (WARNING - this is irreversible); PICC master key settings changeable when authenticated with PICC master key = 1 | 280 // bit 3: PICC master key settings frozen = 0 (WARNING - this is irreversible); PICC master key settings changeable when authenticated with PICC master key = 1 |
280 bit 2: PICC master key authentication required for creating or deleting applications = 0; Authentication not required = 1 | 281 // bit 2: PICC master key authentication required for creating or deleting applications = 0; Authentication not required = 1 |
281 bit 1: PICC master key authentication required for listing of applications or reading key settings = 0; Free listing of applications and reading key settings = 1 | 282 // bit 1: PICC master key authentication required for listing of applications or reading key settings = 0; Free listing of applications and reading key settings = 1 |
282 bit 0: PICC master key frozen (reversible with configuration change or when formatting card) = 0; PICC master key changeable = 1 | 283 // bit 0: PICC master key frozen (reversible with configuration change or when formatting card) = 0; PICC master key changeable = 1 |
283 */ | 284 // */ |
284 | 285 // |
285 #define MDMK_SETTINGS(picc_master_key_settings_changeable,free_create_delete_application,free_listing_apps_and_key_settings,picc_master_key_changeable) ( \ | 286 // #define MDMK_SETTINGS(picc_master_key_settings_changeable,free_create_delete_application,free_listing_apps_and_key_settings,picc_master_key_changeable) ( \ |
286 (picc_master_key_settings_changeable << 3) | \ | 287 // (picc_master_key_settings_changeable << 3) | \ |
287 (free_create_delete_application << 2) | \ | 288 // (free_create_delete_application << 2) | \ |
288 (free_listing_apps_and_key_settings << 1) | \ | 289 // (free_listing_apps_and_key_settings << 1) | \ |
289 (picc_master_key_changeable) \ | 290 // (picc_master_key_changeable) \ |
290 ) | 291 // ) |
291 | 292 // |
292 /* Mifare DESFire EV1 Application crypto operations */ | 293 // /* Mifare DESFire EV1 Application crypto operations */ |
293 | 294 // |
294 #define APPLICATION_CRYPTO_DES 0x00 | 295 // #define APPLICATION_CRYPTO_DES 0x00 |
295 #define APPLICATION_CRYPTO_3K3DES 0x40 | 296 // #define APPLICATION_CRYPTO_3K3DES 0x40 |
296 #define APPLICATION_CRYPTO_AES 0x80 | 297 // #define APPLICATION_CRYPTO_AES 0x80 |
297 | 298 // |
298 /* Mifare DESFire Application settings | 299 // /* Mifare DESFire Application settings |
299 * bit 7 - 4: Number of key needed to change application keys (key 0 - 13; 0 = master key; 14 = key itself required for key change; 15 = all keys are frozen) | 300 // * bit 7 - 4: Number of key needed to change application keys (key 0 - 13; 0 = master key; 14 = key itself required for key change; 15 = all keys are frozen) |
300 * bit 3: Application configuration frozen = 0; Application configuration changeable when authenticated with application master key = 1 | 301 // * bit 3: Application configuration frozen = 0; Application configuration changeable when authenticated with application master key = 1 |
301 * bit 2: Application master key authentication required for create/delete files = 0; Authentication not required = 1 | 302 // * bit 2: Application master key authentication required for create/delete files = 0; Authentication not required = 1 |
302 * bit 1: GetFileIDs, GetFileSettings and GetKeySettings behavior: Master key authentication required = 0; No authentication required = 1 | 303 // * bit 1: GetFileIDs, GetFileSettings and GetKeySettings behavior: Master key authentication required = 0; No authentication required = 1 |
303 * bit 0 = Application master key frozen = 0; Application master key changeable = 1 | 304 // * bit 0 = Application master key frozen = 0; Application master key changeable = 1 |
304 */ | 305 // */ |
305 | 306 // |
306 #define MDAPP_SETTINGS(key_no_for_key_changing,config_changeable,free_create_delete_files,free_listing_contents,app_master_key_changeable) ( \ | 307 // #define MDAPP_SETTINGS(key_no_for_key_changing,config_changeable,free_create_delete_files,free_listing_contents,app_master_key_changeable) ( \ |
307 (key_no_for_key_changing << 4) | \ | 308 // (key_no_for_key_changing << 4) | \ |
308 (config_changeable << 3) | \ | 309 // (config_changeable << 3) | \ |
309 (free_create_delete_files << 2) | \ | 310 // (free_create_delete_files << 2) | \ |
310 (free_listing_contents << 1) | \ | 311 // (free_listing_contents << 1) | \ |
311 (app_master_key_changeable) \ | 312 // (app_master_key_changeable) \ |
312 ) | 313 // ) |
313 | 314 // |
314 /* Access right */ | 315 // /* Access right */ |
315 | 316 // |
316 #define MDAR(read,write,read_write,change_access_rights) ( \ | 317 // #define MDAR(read,write,read_write,change_access_rights) ( \ |
317 (read << 12) | \ | 318 // (read << 12) | \ |
318 (write << 8) | \ | 319 // (write << 8) | \ |
319 (read_write << 4) | \ | 320 // (read_write << 4) | \ |
320 (change_access_rights) \ | 321 // (change_access_rights) \ |
321 ) | 322 // ) |
322 | 323 // |
323 #define MDAR_READ(ar) (((ar) >> 12) & 0x0f) | 324 // #define MDAR_READ(ar) (((ar) >> 12) & 0x0f) |
324 #define MDAR_WRITE(ar) (((ar) >> 8) & 0x0f) | 325 // #define MDAR_WRITE(ar) (((ar) >> 8) & 0x0f) |
325 #define MDAR_READ_WRITE(ar) (((ar) >> 4) & 0x0f) | 326 // #define MDAR_READ_WRITE(ar) (((ar) >> 4) & 0x0f) |
326 #define MDAR_CHANGE_AR(ar) ((ar) & 0x0f) | 327 // #define MDAR_CHANGE_AR(ar) ((ar) & 0x0f) |
327 | 328 // |
328 #define MDAR_KEY0 0x0 | 329 // #define MDAR_KEY0 0x0 |
329 #define MDAR_KEY1 0x1 | 330 // #define MDAR_KEY1 0x1 |
330 #define MDAR_KEY2 0x2 | 331 // #define MDAR_KEY2 0x2 |
331 #define MDAR_KEY3 0x3 | 332 // #define MDAR_KEY3 0x3 |
332 #define MDAR_KEY4 0x4 | 333 // #define MDAR_KEY4 0x4 |
333 #define MDAR_KEY5 0x5 | 334 // #define MDAR_KEY5 0x5 |
334 #define MDAR_KEY6 0x6 | 335 // #define MDAR_KEY6 0x6 |
335 #define MDAR_KEY7 0x7 | 336 // #define MDAR_KEY7 0x7 |
336 #define MDAR_KEY8 0x8 | 337 // #define MDAR_KEY8 0x8 |
337 #define MDAR_KEY9 0x9 | 338 // #define MDAR_KEY9 0x9 |
338 #define MDAR_KEY10 0xa | 339 // #define MDAR_KEY10 0xa |
339 #define MDAR_KEY11 0xb | 340 // #define MDAR_KEY11 0xb |
340 #define MDAR_KEY12 0xc | 341 // #define MDAR_KEY12 0xc |
341 #define MDAR_KEY13 0xd | 342 // #define MDAR_KEY13 0xd |
342 #define MDAR_FREE 0xE | 343 // #define MDAR_FREE 0xE |
343 #define MDAR_DENY 0xF | 344 // #define MDAR_DENY 0xF |
344 | 345 // |
345 /* Status and error codes */ | 346 // /* Status and error codes */ |
346 | 347 // |
347 #define OPERATION_OK 0x00 | 348 // #define OPERATION_OK 0x00 |
348 #define NO_CHANGES 0x0C | 349 // #define NO_CHANGES 0x0C |
349 #define OUT_OF_EEPROM_ERROR 0x0E | 350 // #define OUT_OF_EEPROM_ERROR 0x0E |
350 #define ILLEGAL_COMMAND_CODE 0x1C | 351 // #define ILLEGAL_COMMAND_CODE 0x1C |
351 #define INTEGRITY_ERROR 0x1E | 352 // #define INTEGRITY_ERROR 0x1E |
352 #define NO_SUCH_KEY 0x40 | 353 // #define NO_SUCH_KEY 0x40 |
353 #define LENGTH_ERROR 0x7E | 354 // #define LENGTH_ERROR 0x7E |
354 #define PERMISSION_ERROR 0x9D | 355 // #define PERMISSION_ERROR 0x9D |
355 #define PARAMETER_ERROR 0x9E | 356 // #define PARAMETER_ERROR 0x9E |
356 #define APPLICATION_NOT_FOUND 0xA0 | 357 // #define APPLICATION_NOT_FOUND 0xA0 |
357 #define APPL_INTEGRITY_ERROR 0xA1 | 358 // #define APPL_INTEGRITY_ERROR 0xA1 |
358 #define AUTHENTICATION_ERROR 0xAE | 359 // #define AUTHENTICATION_ERROR 0xAE |
359 #define ADDITIONAL_FRAME 0xAF | 360 // #define ADDITIONAL_FRAME 0xAF |
360 #define BOUNDARY_ERROR 0xBE | 361 // #define BOUNDARY_ERROR 0xBE |
361 #define PICC_INTEGRITY_ERROR 0xC1 | 362 // #define PICC_INTEGRITY_ERROR 0xC1 |
362 #define COMMAND_ABORTED 0xCA | 363 // #define COMMAND_ABORTED 0xCA |
363 #define PICC_DISABLED_ERROR 0xCD | 364 // #define PICC_DISABLED_ERROR 0xCD |
364 #define COUNT_ERROR 0xCE | 365 // #define COUNT_ERROR 0xCE |
365 #define DUPLICATE_ERROR 0xDE | 366 // #define DUPLICATE_ERROR 0xDE |
366 #define EEPROM_ERROR 0xEE | 367 // #define EEPROM_ERROR 0xEE |
367 #define FILE_NOT_FOUND 0xF0 | 368 // #define FILE_NOT_FOUND 0xF0 |
368 #define FILE_INTEGRITY_ERROR 0xF1 | 369 // #define FILE_INTEGRITY_ERROR 0xF1 |
369 | 370 // |
370 /* Error code managed by the library */ | 371 // /* Error code managed by the library */ |
371 | 372 // |
372 #define CRYPTO_ERROR 0x01 | 373 // #define CRYPTO_ERROR 0x01 |
373 #define TAG_INFO_MISSING_ERROR 0xBA | 374 // #define TAG_INFO_MISSING_ERROR 0xBA |
374 #define UNKNOWN_TAG_TYPE_ERROR 0xBB | 375 // #define UNKNOWN_TAG_TYPE_ERROR 0xBB |
375 | 376 // |
376 struct mifare_desfire_aid; | 377 // struct mifare_desfire_aid; |
377 typedef struct mifare_desfire_aid *MifareDESFireAID; | 378 // typedef struct mifare_desfire_aid *MifareDESFireAID; |
378 | 379 // |
379 struct mifare_desfire_df { | 380 // struct mifare_desfire_df { |
380 uint32_t aid; | 381 // uint32_t aid; |
381 uint16_t fid; | 382 // uint16_t fid; |
382 uint8_t df_name[16]; | 383 // uint8_t df_name[16]; |
383 size_t df_name_len; | 384 // size_t df_name_len; |
384 }; | 385 // }; |
385 typedef struct mifare_desfire_df MifareDESFireDF; | 386 // typedef struct mifare_desfire_df MifareDESFireDF; |
386 | 387 // |
387 MifareDESFireAID mifare_desfire_aid_new(uint32_t aid); | 388 // MifareDESFireAID mifare_desfire_aid_new(uint32_t aid); |
388 MifareDESFireAID mifare_desfire_aid_new_with_mad_aid(MadAid mad_aid, uint8_t n); | 389 // MifareDESFireAID mifare_desfire_aid_new_with_mad_aid(MadAid mad_aid, uint8_t n); |
389 uint32_t mifare_desfire_aid_get_aid(MifareDESFireAID aid); | 390 // uint32_t mifare_desfire_aid_get_aid(MifareDESFireAID aid); |
390 | 391 // |
391 uint8_t mifare_desfire_last_pcd_error(FreefareTag tag); | 392 // uint8_t mifare_desfire_last_pcd_error(FreefareTag tag); |
392 uint8_t mifare_desfire_last_picc_error(FreefareTag tag); | 393 // uint8_t mifare_desfire_last_picc_error(FreefareTag tag); |
393 | 394 // |
394 #pragma pack (push) | 395 // #pragma pack (push) |
395 #pragma pack (1) | 396 // #pragma pack (1) |
396 struct mifare_desfire_version_info { | 397 // struct mifare_desfire_version_info { |
397 struct { | 398 // struct { |
398 uint8_t vendor_id; | 399 // uint8_t vendor_id; |
399 uint8_t type; | 400 // uint8_t type; |
400 uint8_t subtype; | 401 // uint8_t subtype; |
401 uint8_t version_major; | 402 // uint8_t version_major; |
402 uint8_t version_minor; | 403 // uint8_t version_minor; |
403 uint8_t storage_size; | 404 // uint8_t storage_size; |
404 uint8_t protocol; | 405 // uint8_t protocol; |
405 } hardware; | 406 // } hardware; |
406 struct { | 407 // struct { |
407 uint8_t vendor_id; | 408 // uint8_t vendor_id; |
408 uint8_t type; | 409 // uint8_t type; |
409 uint8_t subtype; | 410 // uint8_t subtype; |
410 uint8_t version_major; | 411 // uint8_t version_major; |
411 uint8_t version_minor; | 412 // uint8_t version_minor; |
412 uint8_t storage_size; | 413 // uint8_t storage_size; |
413 uint8_t protocol; | 414 // uint8_t protocol; |
414 } software; | 415 // } software; |
415 uint8_t uid[7]; | 416 // uint8_t uid[7]; |
416 uint8_t batch_number[5]; | 417 // uint8_t batch_number[5]; |
417 uint8_t production_week; | 418 // uint8_t production_week; |
418 uint8_t production_year; | 419 // uint8_t production_year; |
419 }; | 420 // }; |
420 #pragma pack (pop) | 421 // #pragma pack (pop) |
421 | 422 // |
422 struct mifare_desfire_file_settings { | 423 // struct mifare_desfire_file_settings { |
423 uint8_t file_type; | 424 // uint8_t file_type; |
424 uint8_t communication_settings; | 425 // uint8_t communication_settings; |
425 uint16_t access_rights; | 426 // uint16_t access_rights; |
426 union { | 427 // union { |
427 struct { | 428 // struct { |
428 uint32_t file_size; | 429 // uint32_t file_size; |
429 } standard_file; | 430 // } standard_file; |
430 struct { | 431 // struct { |
431 int32_t lower_limit; | 432 // int32_t lower_limit; |
432 int32_t upper_limit; | 433 // int32_t upper_limit; |
433 int32_t limited_credit_value; | 434 // int32_t limited_credit_value; |
434 uint8_t limited_credit_enabled; | 435 // uint8_t limited_credit_enabled; |
435 } value_file; | 436 // } value_file; |
436 struct { | 437 // struct { |
437 uint32_t record_size; | 438 // uint32_t record_size; |
438 uint32_t max_number_of_records; | 439 // uint32_t max_number_of_records; |
439 uint32_t current_number_of_records; | 440 // uint32_t current_number_of_records; |
440 } linear_record_file; | 441 // } linear_record_file; |
441 } settings; | 442 // } settings; |
442 }; | 443 // }; |
443 | 444 // |
444 FreefareTag mifare_desfire_tag_new(nfc_device *device, nfc_target target); | 445 // FreefareTag mifare_desfire_tag_new(nfc_device *device, nfc_target target); |
445 void mifare_desfire_tag_free(FreefareTag tags); | 446 // void mifare_desfire_tag_free(FreefareTag tags); |
446 | 447 // |
447 int mifare_desfire_connect(FreefareTag tag); | 448 // int mifare_desfire_connect(FreefareTag tag); |
448 int mifare_desfire_disconnect(FreefareTag tag); | 449 // int mifare_desfire_disconnect(FreefareTag tag); |
449 | 450 // |
450 int mifare_desfire_authenticate(FreefareTag tag, uint8_t key_no, MifareDESFireKey key); | 451 // int mifare_desfire_authenticate(FreefareTag tag, uint8_t key_no, MifareDESFireKey key); |
451 int mifare_desfire_authenticate_iso(FreefareTag tag, uint8_t key_no, MifareDESFireKey key); | 452 // int mifare_desfire_authenticate_iso(FreefareTag tag, uint8_t key_no, MifareDESFireKey key); |
452 int mifare_desfire_authenticate_aes(FreefareTag tag, uint8_t key_no, MifareDESFireKey key); | 453 // int mifare_desfire_authenticate_aes(FreefareTag tag, uint8_t key_no, MifareDESFireKey key); |
453 int mifare_desfire_change_key_settings(FreefareTag tag, uint8_t settings); | 454 // int mifare_desfire_change_key_settings(FreefareTag tag, uint8_t settings); |
454 int mifare_desfire_get_key_settings(FreefareTag tag, uint8_t *settings, uint8_t *max_keys); | 455 // int mifare_desfire_get_key_settings(FreefareTag tag, uint8_t *settings, uint8_t *max_keys); |
455 int mifare_desfire_change_key(FreefareTag tag, uint8_t key_no, MifareDESFireKey new_key, MifareDESFireKey old_key); | 456 // int mifare_desfire_change_key(FreefareTag tag, uint8_t key_no, MifareDESFireKey new_key, MifareDESFireKey old_key); |
456 int mifare_desfire_get_key_version(FreefareTag tag, uint8_t key_no, uint8_t *version); | 457 // int mifare_desfire_get_key_version(FreefareTag tag, uint8_t key_no, uint8_t *version); |
457 int mifare_desfire_create_application(FreefareTag tag, MifareDESFireAID aid, uint8_t settings, uint8_t key_no); | 458 // int mifare_desfire_create_application(FreefareTag tag, MifareDESFireAID aid, uint8_t settings, uint8_t key_no); |
458 int mifare_desfire_create_application_3k3des(FreefareTag tag, MifareDESFireAID aid, uint8_t settings, uint8_t key_no); | 459 // int mifare_desfire_create_application_3k3des(FreefareTag tag, MifareDESFireAID aid, uint8_t settings, uint8_t key_no); |
459 int mifare_desfire_create_application_aes(FreefareTag tag, MifareDESFireAID aid, uint8_t settings, uint8_t key_no); | 460 // int mifare_desfire_create_application_aes(FreefareTag tag, MifareDESFireAID aid, uint8_t settings, uint8_t key_no); |
460 | 461 // |
461 int mifare_desfire_create_application_iso(FreefareTag tag, MifareDESFireAID aid, uint8_t settings, uint8_t key_no, int want_iso_file_identifiers, uint16_t iso_file_id, uint8_t *iso_file_name, size_t iso_file_name_len); | 462 // int mifare_desfire_create_application_iso(FreefareTag tag, MifareDESFireAID aid, uint8_t settings, uint8_t key_no, int want_iso_file_identifiers, uint16_t iso_file_id, uint8_t *iso_file_name, size_t iso_file_name_len); |
462 int mifare_desfire_create_application_3k3des_iso(FreefareTag tag, MifareDESFireAID aid, uint8_t settings, uint8_t key_no, int want_iso_file_identifiers, uint16_t iso_file_id, uint8_t *iso_file_name, size_t iso_file_name_len); | 463 // int mifare_desfire_create_application_3k3des_iso(FreefareTag tag, MifareDESFireAID aid, uint8_t settings, uint8_t key_no, int want_iso_file_identifiers, uint16_t iso_file_id, uint8_t *iso_file_name, size_t iso_file_name_len); |
463 int mifare_desfire_create_application_aes_iso(FreefareTag tag, MifareDESFireAID aid, uint8_t settings, uint8_t key_no, int want_iso_file_identifiers, uint16_t iso_file_id, uint8_t *iso_file_name, size_t iso_file_name_len); | 464 // int mifare_desfire_create_application_aes_iso(FreefareTag tag, MifareDESFireAID aid, uint8_t settings, uint8_t key_no, int want_iso_file_identifiers, uint16_t iso_file_id, uint8_t *iso_file_name, size_t iso_file_name_len); |
464 | 465 // |
465 int mifare_desfire_delete_application(FreefareTag tag, MifareDESFireAID aid); | 466 // int mifare_desfire_delete_application(FreefareTag tag, MifareDESFireAID aid); |
466 int mifare_desfire_get_application_ids(FreefareTag tag, MifareDESFireAID *aids[], size_t *count); | 467 // int mifare_desfire_get_application_ids(FreefareTag tag, MifareDESFireAID *aids[], size_t *count); |
467 int mifare_desfire_get_df_names(FreefareTag tag, MifareDESFireDF *dfs[], size_t *count); | 468 // int mifare_desfire_get_df_names(FreefareTag tag, MifareDESFireDF *dfs[], size_t *count); |
468 void mifare_desfire_free_application_ids(MifareDESFireAID aids[]); | 469 // void mifare_desfire_free_application_ids(MifareDESFireAID aids[]); |
469 int mifare_desfire_select_application(FreefareTag tag, MifareDESFireAID aid); | 470 // int mifare_desfire_select_application(FreefareTag tag, MifareDESFireAID aid); |
470 int mifare_desfire_format_picc(FreefareTag tag); | 471 // int mifare_desfire_format_picc(FreefareTag tag); |
471 int mifare_desfire_get_version(FreefareTag tag, struct mifare_desfire_version_info *version_info); | 472 // int mifare_desfire_get_version(FreefareTag tag, struct mifare_desfire_version_info *version_info); |
472 int mifare_desfire_free_mem(FreefareTag tag, uint32_t *size); | 473 // int mifare_desfire_free_mem(FreefareTag tag, uint32_t *size); |
473 int mifare_desfire_set_configuration(FreefareTag tag, bool disable_format, bool enable_random_uid); | 474 // int mifare_desfire_set_configuration(FreefareTag tag, bool disable_format, bool enable_random_uid); |
474 int mifare_desfire_set_default_key(FreefareTag tag, MifareDESFireKey key); | 475 // int mifare_desfire_set_default_key(FreefareTag tag, MifareDESFireKey key); |
475 int mifare_desfire_set_ats(FreefareTag tag, uint8_t *ats); | 476 // int mifare_desfire_set_ats(FreefareTag tag, uint8_t *ats); |
476 int mifare_desfire_get_card_uid(FreefareTag tag, char **uid); | 477 // int mifare_desfire_get_card_uid(FreefareTag tag, char **uid); |
477 int mifare_desfire_get_card_uid_raw(FreefareTag tag, uint8_t uid[7]); | 478 // int mifare_desfire_get_card_uid_raw(FreefareTag tag, uint8_t uid[7]); |
478 int mifare_desfire_get_file_ids(FreefareTag tag, uint8_t **files, size_t *count); | 479 // int mifare_desfire_get_file_ids(FreefareTag tag, uint8_t **files, size_t *count); |
479 int mifare_desfire_get_iso_file_ids(FreefareTag tag, uint16_t **files, size_t *count); | 480 // int mifare_desfire_get_iso_file_ids(FreefareTag tag, uint16_t **files, size_t *count); |
480 int mifare_desfire_get_file_settings(FreefareTag tag, uint8_t file_no, struct mifare_desfire_file_settings *settings); | 481 // int mifare_desfire_get_file_settings(FreefareTag tag, uint8_t file_no, struct mifare_desfire_file_settings *settings); |
481 int mifare_desfire_change_file_settings(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights); | 482 // int mifare_desfire_change_file_settings(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights); |
482 int mifare_desfire_create_std_data_file(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, uint32_t file_size); | 483 // int mifare_desfire_create_std_data_file(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, uint32_t file_size); |
483 int mifare_desfire_create_std_data_file_iso(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, uint32_t file_size, uint16_t iso_file_id); | 484 // int mifare_desfire_create_std_data_file_iso(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, uint32_t file_size, uint16_t iso_file_id); |
484 int mifare_desfire_create_backup_data_file(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, uint32_t file_size); | 485 // int mifare_desfire_create_backup_data_file(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, uint32_t file_size); |
485 int mifare_desfire_create_backup_data_file_iso(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, uint32_t file_size, uint16_t iso_file_id); | 486 // int mifare_desfire_create_backup_data_file_iso(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, uint32_t file_size, uint16_t iso_file_id); |
486 int mifare_desfire_create_value_file(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, int32_t lower_limit, int32_t upper_limit, int32_t value, uint8_t limited_credit_enable); | 487 // int mifare_desfire_create_value_file(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, int32_t lower_limit, int32_t upper_limit, int32_t value, uint8_t limited_credit_enable); |
487 int mifare_desfire_create_linear_record_file(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, uint32_t record_size, uint32_t max_number_of_records); | 488 // int mifare_desfire_create_linear_record_file(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, uint32_t record_size, uint32_t max_number_of_records); |
488 int mifare_desfire_create_linear_record_file_iso(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, uint32_t record_size, uint32_t max_number_of_records, uint16_t iso_file_id); | 489 // int mifare_desfire_create_linear_record_file_iso(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, uint32_t record_size, uint32_t max_number_of_records, uint16_t iso_file_id); |
489 int mifare_desfire_create_cyclic_record_file(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, uint32_t record_size, uint32_t max_number_of_records); | 490 // int mifare_desfire_create_cyclic_record_file(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, uint32_t record_size, uint32_t max_number_of_records); |
490 int mifare_desfire_create_cyclic_record_file_iso(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, uint32_t record_size, uint32_t max_number_of_records, uint16_t iso_file_id); | 491 // int mifare_desfire_create_cyclic_record_file_iso(FreefareTag tag, uint8_t file_no, uint8_t communication_settings, uint16_t access_rights, uint32_t record_size, uint32_t max_number_of_records, uint16_t iso_file_id); |
491 int mifare_desfire_delete_file(FreefareTag tag, uint8_t file_no); | 492 // int mifare_desfire_delete_file(FreefareTag tag, uint8_t file_no); |
492 | 493 // |
493 ssize_t mifare_desfire_read_data(FreefareTag tag, uint8_t file_no, off_t offset, size_t length, void *data); | 494 // ssize_t mifare_desfire_read_data(FreefareTag tag, uint8_t file_no, off_t offset, size_t length, void *data); |
494 ssize_t mifare_desfire_read_data_ex(FreefareTag tag, uint8_t file_no, off_t offset, size_t length, void *data, int cs); | 495 // ssize_t mifare_desfire_read_data_ex(FreefareTag tag, uint8_t file_no, off_t offset, size_t length, void *data, int cs); |
495 ssize_t mifare_desfire_write_data(FreefareTag tag, uint8_t file_no, off_t offset, size_t length, const void *data); | 496 // ssize_t mifare_desfire_write_data(FreefareTag tag, uint8_t file_no, off_t offset, size_t length, const void *data); |
496 ssize_t mifare_desfire_write_data_ex(FreefareTag tag, uint8_t file_no, off_t offset, size_t length, const void *data, int cs); | 497 // ssize_t mifare_desfire_write_data_ex(FreefareTag tag, uint8_t file_no, off_t offset, size_t length, const void *data, int cs); |
497 int mifare_desfire_get_value(FreefareTag tag, uint8_t file_no, int32_t *value); | 498 // int mifare_desfire_get_value(FreefareTag tag, uint8_t file_no, int32_t *value); |
498 int mifare_desfire_get_value_ex(FreefareTag tag, uint8_t file_no, int32_t *value, int cs); | 499 // int mifare_desfire_get_value_ex(FreefareTag tag, uint8_t file_no, int32_t *value, int cs); |
499 int mifare_desfire_credit(FreefareTag tag, uint8_t file_no, int32_t amount); | 500 // int mifare_desfire_credit(FreefareTag tag, uint8_t file_no, int32_t amount); |
500 int mifare_desfire_credit_ex(FreefareTag tag, uint8_t file_no, int32_t amount, int cs); | 501 // int mifare_desfire_credit_ex(FreefareTag tag, uint8_t file_no, int32_t amount, int cs); |
501 int mifare_desfire_debit(FreefareTag tag, uint8_t file_no, int32_t amount); | 502 // int mifare_desfire_debit(FreefareTag tag, uint8_t file_no, int32_t amount); |
502 int mifare_desfire_debit_ex(FreefareTag tag, uint8_t file_no, int32_t amount, int cs); | 503 // int mifare_desfire_debit_ex(FreefareTag tag, uint8_t file_no, int32_t amount, int cs); |
503 int mifare_desfire_limited_credit(FreefareTag tag, uint8_t file_no, int32_t amount); | 504 // int mifare_desfire_limited_credit(FreefareTag tag, uint8_t file_no, int32_t amount); |
504 int mifare_desfire_limited_credit_ex(FreefareTag tag, uint8_t file_no, int32_t amount, int cs); | 505 // int mifare_desfire_limited_credit_ex(FreefareTag tag, uint8_t file_no, int32_t amount, int cs); |
505 ssize_t mifare_desfire_write_record(FreefareTag tag, uint8_t file_no, off_t offset, size_t length, void *data); | 506 // ssize_t mifare_desfire_write_record(FreefareTag tag, uint8_t file_no, off_t offset, size_t length, void *data); |
506 ssize_t mifare_desfire_write_record_ex(FreefareTag tag, uint8_t file_no, off_t offset, size_t length, void *data, int cs); | 507 // ssize_t mifare_desfire_write_record_ex(FreefareTag tag, uint8_t file_no, off_t offset, size_t length, void *data, int cs); |
507 ssize_t mifare_desfire_read_records(FreefareTag tag, uint8_t file_no, off_t offset, size_t length, void *data); | 508 // ssize_t mifare_desfire_read_records(FreefareTag tag, uint8_t file_no, off_t offset, size_t length, void *data); |
508 ssize_t mifare_desfire_read_records_ex(FreefareTag tag, uint8_t file_no, off_t offset, size_t length, void *data, int cs); | 509 // ssize_t mifare_desfire_read_records_ex(FreefareTag tag, uint8_t file_no, off_t offset, size_t length, void *data, int cs); |
509 int mifare_desfire_clear_record_file(FreefareTag tag, uint8_t file_no); | 510 // int mifare_desfire_clear_record_file(FreefareTag tag, uint8_t file_no); |
510 int mifare_desfire_commit_transaction(FreefareTag tag); | 511 // int mifare_desfire_commit_transaction(FreefareTag tag); |
511 int mifare_desfire_abort_transaction(FreefareTag tag); | 512 // int mifare_desfire_abort_transaction(FreefareTag tag); |
512 | 513 // |
513 MifareDESFireKey mifare_desfire_des_key_new(const uint8_t value[8]); | 514 // MifareDESFireKey mifare_desfire_des_key_new(const uint8_t value[8]); |
514 MifareDESFireKey mifare_desfire_3des_key_new(const uint8_t value[16]); | 515 // MifareDESFireKey mifare_desfire_3des_key_new(const uint8_t value[16]); |
515 MifareDESFireKey mifare_desfire_des_key_new_with_version(const uint8_t value[8]); | 516 // MifareDESFireKey mifare_desfire_des_key_new_with_version(const uint8_t value[8]); |
516 MifareDESFireKey mifare_desfire_3des_key_new_with_version(const uint8_t value[16]); | 517 // MifareDESFireKey mifare_desfire_3des_key_new_with_version(const uint8_t value[16]); |
517 MifareDESFireKey mifare_desfire_3k3des_key_new(const uint8_t value[24]); | 518 // MifareDESFireKey mifare_desfire_3k3des_key_new(const uint8_t value[24]); |
518 MifareDESFireKey mifare_desfire_3k3des_key_new_with_version(const uint8_t value[24]); | 519 // MifareDESFireKey mifare_desfire_3k3des_key_new_with_version(const uint8_t value[24]); |
519 MifareDESFireKey mifare_desfire_aes_key_new(const uint8_t value[16]); | 520 // MifareDESFireKey mifare_desfire_aes_key_new(const uint8_t value[16]); |
520 MifareDESFireKey mifare_desfire_aes_key_new_with_version(const uint8_t value[16], uint8_t version); | 521 // MifareDESFireKey mifare_desfire_aes_key_new_with_version(const uint8_t value[16], uint8_t version); |
521 uint8_t mifare_desfire_key_get_version(MifareDESFireKey key); | 522 // uint8_t mifare_desfire_key_get_version(MifareDESFireKey key); |
522 void mifare_desfire_key_set_version(MifareDESFireKey key, uint8_t version); | 523 // void mifare_desfire_key_set_version(MifareDESFireKey key, uint8_t version); |
523 void mifare_desfire_key_free(MifareDESFireKey key); | 524 // void mifare_desfire_key_free(MifareDESFireKey key); |
524 | 525 // |
525 uint8_t *tlv_encode(const uint8_t type, const uint8_t *istream, uint16_t isize, size_t *osize); | 526 // uint8_t *tlv_encode(const uint8_t type, const uint8_t *istream, uint16_t isize, size_t *osize); |
526 uint8_t *tlv_decode(const uint8_t *istream, uint8_t *type, uint16_t *size); | 527 // uint8_t *tlv_decode(const uint8_t *istream, uint8_t *type, uint16_t *size); |
527 size_t tlv_record_length(const uint8_t *istream, size_t *field_length_size, size_t *field_value_size); | 528 // size_t tlv_record_length(const uint8_t *istream, size_t *field_length_size, size_t *field_value_size); |
528 uint8_t *tlv_append(uint8_t *a, uint8_t *b); | 529 // uint8_t *tlv_append(uint8_t *a, uint8_t *b); |
529 | 530 // |
530 typedef enum mifare_key_type { | 531 // typedef enum mifare_key_type { |
531 MIFARE_KEY_DES, | 532 // MIFARE_KEY_DES, |
532 MIFARE_KEY_2K3DES, | 533 // MIFARE_KEY_2K3DES, |
533 MIFARE_KEY_3K3DES, | 534 // MIFARE_KEY_3K3DES, |
534 MIFARE_KEY_AES128, | 535 // MIFARE_KEY_AES128, |
535 | 536 // |
536 MIFARE_KEY_LAST = MIFARE_KEY_AES128 | 537 // MIFARE_KEY_LAST = MIFARE_KEY_AES128 |
537 } MifareKeyType; | 538 // } MifareKeyType; |
538 | 539 // |
539 struct mifare_key_deriver; | 540 // struct mifare_key_deriver; |
540 typedef struct mifare_key_deriver *MifareKeyDeriver; | 541 // typedef struct mifare_key_deriver *MifareKeyDeriver; |
541 | 542 // |
542 MifareKeyDeriver mifare_key_deriver_new_an10922(MifareDESFireKey master_key, MifareKeyType output_key_type); | 543 // MifareKeyDeriver mifare_key_deriver_new_an10922(MifareDESFireKey master_key, MifareKeyType output_key_type); |
543 int mifare_key_deriver_begin(MifareKeyDeriver deriver); | 544 // int mifare_key_deriver_begin(MifareKeyDeriver deriver); |
544 int mifare_key_deriver_update_data(MifareKeyDeriver deriver, const uint8_t *data, size_t len); | 545 // int mifare_key_deriver_update_data(MifareKeyDeriver deriver, const uint8_t *data, size_t len); |
545 int mifare_key_deriver_update_uid(MifareKeyDeriver deriver, FreefareTag tag); | 546 // int mifare_key_deriver_update_uid(MifareKeyDeriver deriver, FreefareTag tag); |
546 int mifare_key_deriver_update_aid(MifareKeyDeriver deriver, MifareDESFireAID aid); | 547 // int mifare_key_deriver_update_aid(MifareKeyDeriver deriver, MifareDESFireAID aid); |
547 int mifare_key_deriver_update_cstr(MifareKeyDeriver deriver, const char *cstr); | 548 // int mifare_key_deriver_update_cstr(MifareKeyDeriver deriver, const char *cstr); |
548 MifareDESFireKey mifare_key_deriver_end(MifareKeyDeriver deriver); | 549 // MifareDESFireKey mifare_key_deriver_end(MifareKeyDeriver deriver); |
549 int mifare_key_deriver_end_raw(MifareKeyDeriver deriver, uint8_t* diversified_bytes, size_t data_max_len); | 550 // int mifare_key_deriver_end_raw(MifareKeyDeriver deriver, uint8_t* diversified_bytes, size_t data_max_len); |
550 void mifare_key_deriver_free(MifareKeyDeriver state); | 551 // void mifare_key_deriver_free(MifareKeyDeriver state); |
551 | 552 |
552 #ifdef __cplusplus | 553 #ifdef __cplusplus |
553 } | 554 } |
554 #endif // __cplusplus | 555 #endif // __cplusplus |
555 | 556 |