]>
git.zerfleddert.de Git - proxmark3-svn/blob - armsrc/mifareutil.c
1 //-----------------------------------------------------------------------------
2 // Merlok, May 2011, 2012
3 // Many authors, whom made it possible
5 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
6 // at your option, any later version. See the LICENSE.txt file for the text of
8 //-----------------------------------------------------------------------------
9 // Work with mifare cards.
10 //-----------------------------------------------------------------------------
12 #include "proxmark3.h"
19 #include "iso14443crc.h"
20 #include "iso14443a.h"
22 #include "mifareutil.h"
24 int MF_DBGLEVEL
= MF_DBG_ALL
;
27 uint8_t* mifare_get_bigbufptr(void) {
28 return (((uint8_t *)BigBuf
) + MIFARE_BUFF_OFFSET
); // was 3560 - tied to other size changes
30 uint8_t* eml_get_bigbufptr_sendbuf(void) {
31 return (((uint8_t *)BigBuf
) + RECV_CMD_OFFSET
);
33 uint8_t* eml_get_bigbufptr_recbuf(void) {
34 return (((uint8_t *)BigBuf
) + MIFARE_BUFF_OFFSET
);
36 uint8_t* eml_get_bigbufptr_cardmem(void) {
37 return (((uint8_t *)BigBuf
) + CARD_MEMORY
);
41 void mf_crypto1_decrypt(struct Crypto1State
*pcs
, uint8_t *data
, int len
){
46 for (i
= 0; i
< len
; i
++)
47 data
[i
] = crypto1_byte(pcs
, 0x00, 0) ^ data
[i
];
50 for (i
= 0; i
< 4; i
++)
51 bt
|= (crypto1_bit(pcs
, 0, 0) ^ BIT(data
[0], i
)) << i
;
58 void mf_crypto1_encrypt(struct Crypto1State
*pcs
, uint8_t *data
, int len
, uint32_t *par
) {
61 uint32_t mltpl
= 1 << (len
- 1); // for len=18 it=0x20000
63 for (i
= 0; i
< len
; i
++) {
65 data
[i
] = crypto1_byte(pcs
, 0x00, 0) ^ data
[i
];
66 *par
= (*par
>> 1) | ( ((filter(pcs
->odd
) ^ oddparity(bt
)) & 0x01) * mltpl
);
71 uint8_t mf_crypto1_encrypt4bit(struct Crypto1State
*pcs
, uint8_t data
) {
75 for (i
= 0; i
< 4; i
++)
76 bt
|= (crypto1_bit(pcs
, 0, 0) ^ BIT(data
, i
)) << i
;
82 int mifare_sendcmd_short(struct Crypto1State
*pcs
, uint8_t crypted
, uint8_t cmd
, uint8_t data
, uint8_t* answer
, uint32_t *timing
)
84 return mifare_sendcmd_shortex(pcs
, crypted
, cmd
, data
, answer
, NULL
, timing
);
87 int mifare_sendcmd_short_special(struct Crypto1State
*pcs
, uint8_t crypted
, uint8_t cmd
, uint8_t* data
, uint8_t* answer
, uint8_t *timing
)
89 uint8_t dcmd
[8];//, ecmd[4];
93 memcpy(dcmd
+1,data
,5);
94 AppendCrc14443a(dcmd
, 6);
95 //Dbprintf("Data command: %02x", dcmd[0]);
96 //Dbprintf("Data R: %02x %02x %02x %02x %02x %02x %02x", dcmd[1],dcmd[2],dcmd[3],dcmd[4],dcmd[5],dcmd[6],dcmd[7]);
98 //memcpy(ecmd, dcmd, sizeof(dcmd));
99 ReaderTransmit(dcmd
, sizeof(dcmd
), NULL
);
100 int len
= ReaderReceive(answer
);
103 if (MF_DBGLEVEL
>= 1) Dbprintf("Authentication failed. Card timeout.");
110 int mifare_sendcmd_short_mfucauth(struct Crypto1State
*pcs
, uint8_t crypted
, uint8_t cmd
, uint8_t* data
, uint8_t* answer
, uint32_t *timing
)
112 uint8_t dcmd
[19];//, ecmd[4];
117 memcpy(dcmd
+1,data
,16);
118 AppendCrc14443a(dcmd
, 17);
119 //Dbprintf("Data command: %02x", dcmd[0]);
120 //Dbprintf("Data R: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", dcmd[0], dcmd[1],dcmd[2],dcmd[3],dcmd[4],dcmd[5],dcmd[6],dcmd[7],dcmd[8],dcmd[9],dcmd[10],dcmd[11],dcmd[12],dcmd[13],dcmd[14],dcmd[15],dcmd[16],dcmd[17],dcmd[18]);
123 //uint8_t wupa[] = { 0x52 };
124 //ReaderTransmitBitsPar(wupa,7,0, NULL);
126 //if(!ReaderReceive(answer)) return 0;
128 ReaderTransmit(dcmd
, sizeof(dcmd
), timing
);
129 len
= ReaderReceive(answer
);
132 if (MF_DBGLEVEL
>= 1) Dbprintf("Authentication failed. Card timeout.");
133 len
= ReaderReceive(answer
);
137 if (MF_DBGLEVEL
>= 1) Dbprintf("NAK - Authentication failed.");
143 int mifare_sendcmd_shortex(struct Crypto1State
*pcs
, uint8_t crypted
, uint8_t cmd
, uint8_t data
, uint8_t* answer
, uint32_t * parptr
, uint32_t *timing
)
145 uint8_t dcmd
[4], ecmd
[4];
146 uint32_t pos
, par
, res
;
150 AppendCrc14443a(dcmd
, 2);
152 memcpy(ecmd
, dcmd
, sizeof(dcmd
));
156 for (pos
= 0; pos
< 4; pos
++)
158 ecmd
[pos
] = crypto1_byte(pcs
, 0x00, 0) ^ dcmd
[pos
];
159 par
= (par
>> 1) | ( ((filter(pcs
->odd
) ^ oddparity(dcmd
[pos
])) & 0x01) * 0x08 );
162 ReaderTransmitPar(ecmd
, sizeof(ecmd
), par
, timing
);
165 ReaderTransmit(dcmd
, sizeof(dcmd
), timing
);
168 int len
= ReaderReceivePar(answer
, &par
);
170 if (parptr
) *parptr
= par
;
172 if (crypted
== CRYPT_ALL
) {
175 for (pos
= 0; pos
< 4; pos
++)
176 res
|= (crypto1_bit(pcs
, 0, 0) ^ BIT(answer
[0], pos
)) << pos
;
181 for (pos
= 0; pos
< len
; pos
++)
183 answer
[pos
] = crypto1_byte(pcs
, 0x00, 0) ^ answer
[pos
];
192 int mifare_classic_auth(struct Crypto1State
*pcs
, uint32_t uid
, uint8_t blockNo
, uint8_t keyType
, uint64_t ui64Key
, uint64_t isNested
)
194 return mifare_classic_authex(pcs
, uid
, blockNo
, keyType
, ui64Key
, isNested
, NULL
, NULL
);
197 int mifare_classic_authex(struct Crypto1State
*pcs
, uint32_t uid
, uint8_t blockNo
, uint8_t keyType
, uint64_t ui64Key
, uint64_t isNested
, uint32_t * ntptr
, uint32_t *timing
)
205 uint32_t nt
, ntpp
; // Supplied tag nonce
207 uint8_t mf_nr_ar
[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
208 uint8_t* receivedAnswer
= mifare_get_bigbufptr();
210 // Transmit MIFARE_CLASSIC_AUTH
211 len
= mifare_sendcmd_short(pcs
, isNested
, 0x60 + (keyType
& 0x01), blockNo
, receivedAnswer
, timing
);
212 if (MF_DBGLEVEL
>= 4) Dbprintf("rand nonce len: %x", len
);
213 if (len
!= 4) return 1;
220 // Save the tag nonce (nt)
221 nt
= bytes_to_num(receivedAnswer
, 4);
223 // ----------------------------- crypto1 create
225 crypto1_destroy(pcs
);
227 // Init cipher with key
228 crypto1_create(pcs
, ui64Key
);
230 if (isNested
== AUTH_NESTED
) {
231 // decrypt nt with help of new key
232 nt
= crypto1_word(pcs
, nt
^ uid
, 1) ^ nt
;
234 // Load (plain) uid^nt into the cipher
235 crypto1_word(pcs
, nt
^ uid
, 0);
239 if (!ntptr
&& (MF_DBGLEVEL
>= 3))
240 Dbprintf("auth uid: %08x nt: %08x", uid
, nt
);
247 // Generate (encrypted) nr+parity by loading it into the cipher (Nr)
248 for (pos
= 0; pos
< 4; pos
++)
250 mf_nr_ar
[pos
] = crypto1_byte(pcs
, ar
[pos
], 0) ^ ar
[pos
];
251 par
= (par
>> 1) | ( ((filter(pcs
->odd
) ^ oddparity(ar
[pos
])) & 0x01) * 0x80 );
254 // Skip 32 bits in pseudo random generator
255 nt
= prng_successor(nt
,32);
258 for (pos
= 4; pos
< 8; pos
++)
260 nt
= prng_successor(nt
,8);
261 mf_nr_ar
[pos
] = crypto1_byte(pcs
,0x00,0) ^ (nt
& 0xff);
262 par
= (par
>> 1)| ( ((filter(pcs
->odd
) ^ oddparity(nt
& 0xff)) & 0x01) * 0x80 );
265 // Transmit reader nonce and reader answer
266 ReaderTransmitPar(mf_nr_ar
, sizeof(mf_nr_ar
), par
, NULL
);
268 // Receive 4 bit answer
269 len
= ReaderReceive(receivedAnswer
);
272 if (MF_DBGLEVEL
>= 1) Dbprintf("Authentication failed. Card timeout.");
276 memcpy(tmp4
, receivedAnswer
, 4);
277 ntpp
= prng_successor(nt
, 32) ^ crypto1_word(pcs
, 0,0);
279 if (ntpp
!= bytes_to_num(tmp4
, 4)) {
280 if (MF_DBGLEVEL
>= 1) Dbprintf("Authentication failed. Error card response.");
287 int mifare_classic_readblock(struct Crypto1State
*pcs
, uint32_t uid
, uint8_t blockNo
, uint8_t *blockData
)
293 uint8_t* receivedAnswer
= mifare_get_bigbufptr();
295 // command MIFARE_CLASSIC_READBLOCK
296 len
= mifare_sendcmd_short(pcs
, 1, 0x30, blockNo
, receivedAnswer
, NULL
);
298 if (MF_DBGLEVEL
>= 1) Dbprintf("Cmd Error: %02x", receivedAnswer
[0]);
302 if (MF_DBGLEVEL
>= 1) Dbprintf("Cmd Error: card timeout. len: %x", len
);
306 memcpy(bt
, receivedAnswer
+ 16, 2);
307 AppendCrc14443a(receivedAnswer
, 16);
308 if (bt
[0] != receivedAnswer
[16] || bt
[1] != receivedAnswer
[17]) {
309 if (MF_DBGLEVEL
>= 1) Dbprintf("Cmd CRC response error.");
313 memcpy(blockData
, receivedAnswer
, 16);
317 int mifare_ultra_auth1(uint32_t uid
, uint8_t *blockData
){
321 uint8_t* receivedAnswer
= mifare_get_bigbufptr();
323 // command MIFARE_CLASSIC_READBLOCK
324 len
= mifare_sendcmd_short(NULL
, 1, 0x1A, 0x00, receivedAnswer
,NULL
);
326 if (MF_DBGLEVEL
>= 1) Dbprintf("Cmd Error: %02x", receivedAnswer
[0]);
330 if (MF_DBGLEVEL
>= 1) Dbprintf("Auth1 Resp: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
331 receivedAnswer
[0],receivedAnswer
[1],receivedAnswer
[2],receivedAnswer
[3],receivedAnswer
[4],
332 receivedAnswer
[5],receivedAnswer
[6],receivedAnswer
[7],receivedAnswer
[8],receivedAnswer
[9],
334 memcpy(blockData
, receivedAnswer
, 11);
337 //else something went wrong???
341 int mifare_ultra_auth2(uint32_t uid
, uint8_t *key
, uint8_t *blockData
){
345 uint8_t* receivedAnswer
= mifare_get_bigbufptr();
348 // command MIFARE_CLASSIC_READBLOCK
349 len
= mifare_sendcmd_short_mfucauth(NULL
, 1, 0xAF, key
, receivedAnswer
,NULL
);
351 if (MF_DBGLEVEL
>= 1) Dbprintf("Cmd Error: %02x", receivedAnswer
[0]);
355 if (MF_DBGLEVEL
>= 1) Dbprintf("Auth2 Resp: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
356 receivedAnswer
[0],receivedAnswer
[1],receivedAnswer
[2],receivedAnswer
[3],receivedAnswer
[4],
357 receivedAnswer
[5],receivedAnswer
[6],receivedAnswer
[7],receivedAnswer
[8],receivedAnswer
[9],
359 memcpy(blockData
, receivedAnswer
, 11);
362 //something went wrong?
366 int mifare_ultra_readblock(uint32_t uid
, uint8_t blockNo
, uint8_t *blockData
)
372 uint8_t* receivedAnswer
= mifare_get_bigbufptr();
374 // command MIFARE_CLASSIC_READBLOCK
375 len
= mifare_sendcmd_short(NULL
, 1, 0x30, blockNo
, receivedAnswer
,NULL
);
377 if (MF_DBGLEVEL
>= 1) Dbprintf("Cmd Error: %02x", receivedAnswer
[0]);
381 if (MF_DBGLEVEL
>= 1) Dbprintf("Cmd Error: card timeout. len: %x", len
);
385 memcpy(bt
, receivedAnswer
+ 16, 2);
386 AppendCrc14443a(receivedAnswer
, 16);
387 if (bt
[0] != receivedAnswer
[16] || bt
[1] != receivedAnswer
[17]) {
388 if (MF_DBGLEVEL
>= 1) Dbprintf("Cmd CRC response error.");
392 memcpy(blockData
, receivedAnswer
, 14);
397 int mifare_classic_writeblock(struct Crypto1State
*pcs
, uint32_t uid
, uint8_t blockNo
, uint8_t *blockData
)
405 uint8_t d_block
[18], d_block_enc
[18];
406 uint8_t* receivedAnswer
= mifare_get_bigbufptr();
408 // command MIFARE_CLASSIC_WRITEBLOCK
409 len
= mifare_sendcmd_short(pcs
, 1, 0xA0, blockNo
, receivedAnswer
, NULL
);
411 if ((len
!= 1) || (receivedAnswer
[0] != 0x0A)) { // 0x0a - ACK
412 if (MF_DBGLEVEL
>= 1) Dbprintf("Cmd Error: %02x", receivedAnswer
[0]);
416 memcpy(d_block
, blockData
, 16);
417 AppendCrc14443a(d_block
, 16);
421 for (pos
= 0; pos
< 18; pos
++)
423 d_block_enc
[pos
] = crypto1_byte(pcs
, 0x00, 0) ^ d_block
[pos
];
424 par
= (par
>> 1) | ( ((filter(pcs
->odd
) ^ oddparity(d_block
[pos
])) & 0x01) * 0x20000 );
427 ReaderTransmitPar(d_block_enc
, sizeof(d_block_enc
), par
, NULL
);
429 // Receive the response
430 len
= ReaderReceive(receivedAnswer
);
433 for (i
= 0; i
< 4; i
++)
434 res
|= (crypto1_bit(pcs
, 0, 0) ^ BIT(receivedAnswer
[0], i
)) << i
;
436 if ((len
!= 1) || (res
!= 0x0A)) {
437 if (MF_DBGLEVEL
>= 1) Dbprintf("Cmd send data2 Error: %02x", res
);
444 int mifare_ultra_writeblock(uint32_t uid
, uint8_t blockNo
, uint8_t *blockData
)
451 uint8_t* receivedAnswer
= mifare_get_bigbufptr();
453 // command MIFARE_CLASSIC_WRITEBLOCK
454 len
= mifare_sendcmd_short(NULL
, 1, 0xA0, blockNo
, receivedAnswer
,NULL
);
456 if ((len
!= 1) || (receivedAnswer
[0] != 0x0A)) { // 0x0a - ACK
457 if (MF_DBGLEVEL
>= 1) Dbprintf("Cmd Addr Error: %02x", receivedAnswer
[0]);
461 memset(d_block
,'\0',18);
462 memcpy(d_block
, blockData
, 16);
463 AppendCrc14443a(d_block
, 16);
465 ReaderTransmitPar(d_block
, sizeof(d_block
), par
, NULL
);
467 // Receive the response
468 len
= ReaderReceive(receivedAnswer
);
470 if ((len
!= 1) || (receivedAnswer
[0] != 0x0A)) { // 0x0a - ACK
471 if (MF_DBGLEVEL
>= 1) Dbprintf("Cmd Data Error: %02x %d", receivedAnswer
[0],len
);
478 int mifare_ultra_special_writeblock(uint32_t uid
, uint8_t blockNo
, uint8_t *blockData
)
485 uint8_t* receivedAnswer
= mifare_get_bigbufptr();
487 // command MIFARE_CLASSIC_WRITEBLOCK
488 memset(d_block
,'\0',8);
490 memcpy(d_block
+1,blockData
,4);
491 AppendCrc14443a(d_block
, 6);
493 //i know the data send here is correct
494 len
= mifare_sendcmd_short_special(NULL
, 1, 0xA2, d_block
, receivedAnswer
,NULL
);
496 if (receivedAnswer
[0] != 0x0A) { // 0x0a - ACK
497 if (MF_DBGLEVEL
>= 1) Dbprintf("Cmd Send Error: %02x %d", receivedAnswer
[0],len
);
503 int mifare_classic_halt(struct Crypto1State
*pcs
, uint32_t uid
)
509 uint8_t* receivedAnswer
= mifare_get_bigbufptr();
511 len
= mifare_sendcmd_short(pcs
, pcs
== NULL
? 0:1, 0x50, 0x00, receivedAnswer
, NULL
);
513 if (MF_DBGLEVEL
>= 1) Dbprintf("halt error. response len: %x", len
);
520 int mifare_ultra_halt(uint32_t uid
)
526 uint8_t* receivedAnswer
= mifare_get_bigbufptr();
528 len
= mifare_sendcmd_short(NULL
, 1, 0x50, 0x00, receivedAnswer
, NULL
);
530 if (MF_DBGLEVEL
>= 1) Dbprintf("halt error. response len: %x", len
);
537 // work with emulator memory
538 void emlSetMem(uint8_t *data
, int blockNum
, int blocksCount
) {
539 uint8_t* emCARD
= eml_get_bigbufptr_cardmem();
541 memcpy(emCARD
+ blockNum
* 16, data
, blocksCount
* 16);
544 void emlGetMem(uint8_t *data
, int blockNum
, int blocksCount
) {
545 uint8_t* emCARD
= eml_get_bigbufptr_cardmem();
547 memcpy(data
, emCARD
+ blockNum
* 16, blocksCount
* 16);
550 void emlGetMemBt(uint8_t *data
, int bytePtr
, int byteCount
) {
551 uint8_t* emCARD
= eml_get_bigbufptr_cardmem();
553 memcpy(data
, emCARD
+ bytePtr
, byteCount
);
556 int emlCheckValBl(int blockNum
) {
557 uint8_t* emCARD
= eml_get_bigbufptr_cardmem();
558 uint8_t* data
= emCARD
+ blockNum
* 16;
560 if ((data
[0] != (data
[4] ^ 0xff)) || (data
[0] != data
[8]) ||
561 (data
[1] != (data
[5] ^ 0xff)) || (data
[1] != data
[9]) ||
562 (data
[2] != (data
[6] ^ 0xff)) || (data
[2] != data
[10]) ||
563 (data
[3] != (data
[7] ^ 0xff)) || (data
[3] != data
[11]) ||
564 (data
[12] != (data
[13] ^ 0xff)) || (data
[12] != data
[14]) ||
565 (data
[12] != (data
[15] ^ 0xff))
571 int emlGetValBl(uint32_t *blReg
, uint8_t *blBlock
, int blockNum
) {
572 uint8_t* emCARD
= eml_get_bigbufptr_cardmem();
573 uint8_t* data
= emCARD
+ blockNum
* 16;
575 if (emlCheckValBl(blockNum
)) {
579 memcpy(blReg
, data
, 4);
585 int emlSetValBl(uint32_t blReg
, uint8_t blBlock
, int blockNum
) {
586 uint8_t* emCARD
= eml_get_bigbufptr_cardmem();
587 uint8_t* data
= emCARD
+ blockNum
* 16;
589 memcpy(data
+ 0, &blReg
, 4);
590 memcpy(data
+ 8, &blReg
, 4);
591 blReg
= blReg
^ 0xffffffff;
592 memcpy(data
+ 4, &blReg
, 4);
595 data
[13] = blBlock
^ 0xff;
597 data
[15] = blBlock
^ 0xff;
602 uint64_t emlGetKey(int sectorNum
, int keyType
) {
604 uint8_t* emCARD
= eml_get_bigbufptr_cardmem();
606 memcpy(key
, emCARD
+ 3 * 16 + sectorNum
* 4 * 16 + keyType
* 10, 6);
607 return bytes_to_num(key
, 6);
610 void emlClearMem(void) {
613 const uint8_t trailer
[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x80, 0x69, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
614 const uint8_t uid
[] = {0xe6, 0x84, 0x87, 0xf3, 0x16, 0x88, 0x04, 0x00, 0x46, 0x8e, 0x45, 0x55, 0x4d, 0x70, 0x41, 0x04};
615 uint8_t* emCARD
= eml_get_bigbufptr_cardmem();
617 memset(emCARD
, 0, CARD_MEMORY_LEN
);
619 // fill sectors trailer data
620 for(b
= 3; b
< 256; b
<127?(b
+=4):(b
+=16)) {
621 emlSetMem((uint8_t *)trailer
, b
, 1);
625 emlSetMem((uint8_t *)uid
, 0, 1);
633 int mifare_sendcmd_special(struct Crypto1State
*pcs
, uint8_t crypted
, uint8_t cmd
, uint8_t* data
, uint8_t* answer
, uint8_t *timing
)
635 uint8_t dcmd
[5];//, ecmd[4];
636 //dcmd= (uint8_t *) malloc(data_len+3);
640 memcpy(dcmd
+1,data
,2);
641 AppendCrc14443a(dcmd
, 3);
642 //Dbprintf("Data command: %02x", dcmd[0]);
643 //Dbprintf("Data R: %02x %02x", dcmd[1],dcmd[2]);
645 //memcpy(ecmd, dcmd, sizeof(dcmd));
646 ReaderTransmit(dcmd
, sizeof(dcmd
), NULL
);
647 int len
= ReaderReceive(answer
);
650 if (MF_DBGLEVEL
>= 1) Dbprintf("Authentication failed. Card timeout.");
658 int mifare_sendcmd_special2(struct Crypto1State
*pcs
, uint8_t crypted
, uint8_t cmd
, uint8_t* data
, uint8_t* answer
, uint8_t *timing
)
660 uint8_t dcmd
[20];//, ecmd[4];
661 //dcmd= (uint8_t *) malloc(data_len+3);
665 memcpy(dcmd
+1,data
,17);
666 AppendCrc14443a(dcmd
, 18);
667 //Dbprintf("Data command: %02x", dcmd[0]);
668 //Dbprintf("Data R: %02x %02x %02x %02x", dcmd[1],dcmd[2],dcmd[3],dcmd[4]);
670 //memcpy(ecmd, dcmd, sizeof(dcmd));
671 ReaderTransmit(dcmd
, sizeof(dcmd
), NULL
);
672 int len
= ReaderReceive(answer
);
675 if (MF_DBGLEVEL
>= 1) Dbprintf("Authentication failed. Card timeout.");
682 int mifare_desfire_des_auth1(uint32_t uid
, uint8_t *blockData
){
685 // load key, keynumber
686 uint8_t data
[2]={0x0a, 0x00};
687 //uint8_t data_len=2;
688 uint8_t* receivedAnswer
= mifare_get_bigbufptr();
690 // command MIFARE_CLASSIC_READBLOCK
691 len
= mifare_sendcmd_special(NULL
, 1, 0x02, data
, receivedAnswer
,NULL
);
693 if (MF_DBGLEVEL
>= 1) Dbprintf("Cmd Error: %02x", receivedAnswer
[0]);
697 if (MF_DBGLEVEL
>= 1) Dbprintf("Auth1 Resp: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
698 receivedAnswer
[0],receivedAnswer
[1],receivedAnswer
[2],receivedAnswer
[3],receivedAnswer
[4],
699 receivedAnswer
[5],receivedAnswer
[6],receivedAnswer
[7],receivedAnswer
[8],receivedAnswer
[9],
700 receivedAnswer
[10],receivedAnswer
[11]);
701 memcpy(blockData
, receivedAnswer
, 12);
704 //else something went wrong???
708 int mifare_desfire_des_auth2(uint32_t uid
, uint8_t *key
, uint8_t *blockData
){
711 uint8_t data
[17]={0xaf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
712 memcpy(data
+1,key
,16);
713 uint8_t* receivedAnswer
= mifare_get_bigbufptr();
716 // command MIFARE_CLASSIC_READBLOCK
717 len
= mifare_sendcmd_special2(NULL
, 1, 0x03, data
, receivedAnswer
,NULL
);
718 if ((receivedAnswer
[0] == 0x03)&&(receivedAnswer
[1] == 0xae)) {
719 if (MF_DBGLEVEL
>= 1) Dbprintf("Auth Error: %02x %02x", receivedAnswer
[0], receivedAnswer
[1]);
723 if (MF_DBGLEVEL
>= 1) Dbprintf("Auth2 Resp: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
724 receivedAnswer
[0],receivedAnswer
[1],receivedAnswer
[2],receivedAnswer
[3],receivedAnswer
[4],
725 receivedAnswer
[5],receivedAnswer
[6],receivedAnswer
[7],receivedAnswer
[8],receivedAnswer
[9],
726 receivedAnswer
[10],receivedAnswer
[11]);
727 memcpy(blockData
, receivedAnswer
, 12);
730 //something went wrong?