]> cvs.zerfleddert.de Git - proxmark3-svn/blob - armsrc/mifarecmd.c
1e42d5b45875e097cb2c753bde2f2169e4286a27
[proxmark3-svn] / armsrc / mifarecmd.c
1 //-----------------------------------------------------------------------------
2 // Merlok - June 2011, 2012
3 // Gerhard de Koning Gans - May 2008
4 // Hagen Fritsch - June 2010
5 // Midnitesnake - Dec 2013
6 // Andy Davies - Apr 2014
7 // Iceman - May 2014
8 //
9 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
10 // at your option, any later version. See the LICENSE.txt file for the text of
11 // the license.
12 //-----------------------------------------------------------------------------
13 // Routines to support ISO 14443 type A.
14 //-----------------------------------------------------------------------------
15
16 #include "mifarecmd.h"
17 #include "apps.h"
18 #include "util.h"
19 #include "crc.h"
20 #include "protocols.h"
21
22 //-----------------------------------------------------------------------------
23 // Select, Authenticate, Read a MIFARE tag.
24 // read block
25 //-----------------------------------------------------------------------------
26 void MifareReadBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
27 {
28 // params
29 uint8_t blockNo = arg0;
30 uint8_t keyType = arg1;
31 uint64_t ui64Key = 0;
32 ui64Key = bytes_to_num(datain, 6);
33
34 // variables
35 byte_t isOK = 0;
36 byte_t dataoutbuf[16];
37 uint8_t uid[10];
38 uint32_t cuid;
39 struct Crypto1State mpcs = {0, 0};
40 struct Crypto1State *pcs;
41 pcs = &mpcs;
42
43 iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
44
45 clear_trace();
46
47 LED_A_ON();
48 LED_B_OFF();
49 LED_C_OFF();
50
51 while (true) {
52 if(!iso14443a_select_card(uid, NULL, &cuid)) {
53 if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");
54 break;
55 };
56
57 if(mifare_classic_auth(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST)) {
58 if (MF_DBGLEVEL >= 1) Dbprintf("Auth error");
59 break;
60 };
61
62 if(mifare_classic_readblock(pcs, cuid, blockNo, dataoutbuf)) {
63 if (MF_DBGLEVEL >= 1) Dbprintf("Read block error");
64 break;
65 };
66
67 if(mifare_classic_halt(pcs, cuid)) {
68 if (MF_DBGLEVEL >= 1) Dbprintf("Halt error");
69 break;
70 };
71
72 isOK = 1;
73 break;
74 }
75
76 // ----------------------------- crypto1 destroy
77 crypto1_destroy(pcs);
78
79 if (MF_DBGLEVEL >= 2) DbpString("READ BLOCK FINISHED");
80
81 LED_B_ON();
82 cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,16);
83 LED_B_OFF();
84
85 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
86 LEDsoff();
87 }
88
89 void MifareUC_Auth(uint8_t arg0, uint8_t *keybytes){
90
91 bool turnOffField = (arg0 == 1);
92
93 LED_A_ON(); LED_B_OFF(); LED_C_OFF();
94
95 iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
96
97 clear_trace();
98
99 if(!iso14443a_select_card(NULL, NULL, NULL)) {
100 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Can't select card");
101 OnError(0);
102 return;
103 };
104
105 if(!mifare_ultra_auth(keybytes)){
106 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Authentication failed");
107 OnError(1);
108 return;
109 }
110
111 if (turnOffField) {
112 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
113 LEDsoff();
114 }
115 cmd_send(CMD_ACK,1,0,0,0,0);
116 }
117
118 // Arg0 = BlockNo,
119 // Arg1 = UsePwd bool
120 // datain = PWD bytes,
121 void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain)
122 {
123 uint8_t blockNo = arg0;
124 byte_t dataout[16] = {0x00};
125 bool useKey = (arg1 == 1); //UL_C
126 bool usePwd = (arg1 == 2); //UL_EV1/NTAG
127
128 LEDsoff();
129 LED_A_ON();
130 iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
131
132 clear_trace();
133
134 int len = iso14443a_select_card(NULL, NULL, NULL);
135 if(!len) {
136 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Can't select card (RC:%02X)",len);
137 OnError(1);
138 return;
139 }
140
141 // UL-C authentication
142 if ( useKey ) {
143 uint8_t key[16] = {0x00};
144 memcpy(key, datain, sizeof(key) );
145
146 if ( !mifare_ultra_auth(key) ) {
147 OnError(1);
148 return;
149 }
150 }
151
152 // UL-EV1 / NTAG authentication
153 if ( usePwd ) {
154 uint8_t pwd[4] = {0x00};
155 memcpy(pwd, datain, 4);
156 uint8_t pack[4] = {0,0,0,0};
157 if (!mifare_ul_ev1_auth(pwd, pack)) {
158 OnError(1);
159 return;
160 }
161 }
162
163 if( mifare_ultra_readblock(blockNo, dataout) ) {
164 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Read block error");
165 OnError(2);
166 return;
167 }
168
169 if( mifare_ultra_halt() ) {
170 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Halt error");
171 OnError(3);
172 return;
173 }
174
175 cmd_send(CMD_ACK,1,0,0,dataout,16);
176 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
177 LEDsoff();
178 }
179
180 //-----------------------------------------------------------------------------
181 // Select, Authenticate, Read a MIFARE tag.
182 // read sector (data = 4 x 16 bytes = 64 bytes, or 16 x 16 bytes = 256 bytes)
183 //-----------------------------------------------------------------------------
184 void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
185 {
186 // params
187 uint8_t sectorNo = arg0;
188 uint8_t keyType = arg1;
189 uint64_t ui64Key = 0;
190 ui64Key = bytes_to_num(datain, 6);
191
192 // variables
193 byte_t isOK = 0;
194 byte_t dataoutbuf[16 * 16];
195 uint8_t uid[10];
196 uint32_t cuid;
197 struct Crypto1State mpcs = {0, 0};
198 struct Crypto1State *pcs;
199 pcs = &mpcs;
200
201 iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
202
203 clear_trace();
204
205 LED_A_ON();
206 LED_B_OFF();
207 LED_C_OFF();
208
209 isOK = 1;
210 if(!iso14443a_select_card(uid, NULL, &cuid)) {
211 isOK = 0;
212 if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");
213 }
214
215
216 if(isOK && mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keyType, ui64Key, AUTH_FIRST)) {
217 isOK = 0;
218 if (MF_DBGLEVEL >= 1) Dbprintf("Auth error");
219 }
220
221 for (uint8_t blockNo = 0; isOK && blockNo < NumBlocksPerSector(sectorNo); blockNo++) {
222 if(mifare_classic_readblock(pcs, cuid, FirstBlockOfSector(sectorNo) + blockNo, dataoutbuf + 16 * blockNo)) {
223 isOK = 0;
224 if (MF_DBGLEVEL >= 1) Dbprintf("Read sector %2d block %2d error", sectorNo, blockNo);
225 break;
226 }
227 }
228
229 if(mifare_classic_halt(pcs, cuid)) {
230 if (MF_DBGLEVEL >= 1) Dbprintf("Halt error");
231 }
232
233 // ----------------------------- crypto1 destroy
234 crypto1_destroy(pcs);
235
236 if (MF_DBGLEVEL >= 2) DbpString("READ SECTOR FINISHED");
237
238 LED_B_ON();
239 cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,16*NumBlocksPerSector(sectorNo));
240 LED_B_OFF();
241
242 // Thats it...
243 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
244 LEDsoff();
245 }
246
247 // arg0 = blockNo (start)
248 // arg1 = Pages (number of blocks)
249 // arg2 = useKey
250 // datain = KEY bytes
251 void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
252 {
253 LEDsoff();
254 LED_A_ON();
255 iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
256
257 // free eventually allocated BigBuf memory
258 BigBuf_free();
259 clear_trace();
260
261 // params
262 uint8_t blockNo = arg0;
263 uint16_t blocks = arg1;
264 bool useKey = (arg2 == 1); //UL_C
265 bool usePwd = (arg2 == 2); //UL_EV1/NTAG
266 uint32_t countblocks = 0;
267 uint8_t *dataout = BigBuf_malloc(CARD_MEMORY_SIZE);
268 if (dataout == NULL){
269 Dbprintf("out of memory");
270 OnError(1);
271 return;
272 }
273
274 int len = iso14443a_select_card(NULL, NULL, NULL);
275 if (!len) {
276 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Can't select card (RC:%d)",len);
277 OnError(1);
278 return;
279 }
280
281 // UL-C authentication
282 if ( useKey ) {
283 uint8_t key[16] = {0x00};
284 memcpy(key, datain, sizeof(key) );
285
286 if ( !mifare_ultra_auth(key) ) {
287 OnError(1);
288 return;
289 }
290 }
291
292 // UL-EV1 / NTAG authentication
293 if (usePwd) {
294 uint8_t pwd[4] = {0x00};
295 memcpy(pwd, datain, sizeof(pwd));
296 uint8_t pack[4] = {0,0,0,0};
297
298 if (!mifare_ul_ev1_auth(pwd, pack)){
299 OnError(1);
300 return;
301 }
302 }
303
304 for (int i = 0; i < blocks; i++){
305 if ((i*4) + 4 >= CARD_MEMORY_SIZE) {
306 Dbprintf("Data exceeds buffer!!");
307 break;
308 }
309
310 len = mifare_ultra_readblock(blockNo + i, dataout + 4 * i);
311
312 if (len) {
313 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Read block %d error",i);
314 // if no blocks read - error out
315 if (i==0){
316 OnError(2);
317 return;
318 } else {
319 //stop at last successful read block and return what we got
320 break;
321 }
322 } else {
323 countblocks++;
324 }
325 }
326
327 len = mifare_ultra_halt();
328 if (len) {
329 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Halt error");
330 OnError(3);
331 return;
332 }
333
334 if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Blocks read %d", countblocks);
335
336 countblocks *= 4;
337
338 cmd_send(CMD_ACK, 1, countblocks, BigBuf_max_traceLen(), 0, 0);
339 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
340 LEDsoff();
341 BigBuf_free();
342 }
343
344 //-----------------------------------------------------------------------------
345 // Select, Authenticate, Write a MIFARE tag.
346 // read block
347 //-----------------------------------------------------------------------------
348 void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
349 {
350 // params
351 uint8_t blockNo = arg0;
352 uint8_t keyType = arg1;
353 uint64_t ui64Key = 0;
354 byte_t blockdata[16];
355
356 ui64Key = bytes_to_num(datain, 6);
357 memcpy(blockdata, datain + 10, 16);
358
359 // variables
360 byte_t isOK = 0;
361 uint8_t uid[10];
362 uint32_t cuid;
363 struct Crypto1State mpcs = {0, 0};
364 struct Crypto1State *pcs;
365 pcs = &mpcs;
366
367 iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
368
369 clear_trace();
370
371 LED_A_ON();
372 LED_B_OFF();
373 LED_C_OFF();
374
375 while (true) {
376 if(!iso14443a_select_card(uid, NULL, &cuid)) {
377 if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");
378 break;
379 };
380
381 if(mifare_classic_auth(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST)) {
382 if (MF_DBGLEVEL >= 1) Dbprintf("Auth error");
383 break;
384 };
385
386 if(mifare_classic_writeblock(pcs, cuid, blockNo, blockdata)) {
387 if (MF_DBGLEVEL >= 1) Dbprintf("Write block error");
388 break;
389 };
390
391 if(mifare_classic_halt(pcs, cuid)) {
392 if (MF_DBGLEVEL >= 1) Dbprintf("Halt error");
393 break;
394 };
395
396 isOK = 1;
397 break;
398 }
399
400 // ----------------------------- crypto1 destroy
401 crypto1_destroy(pcs);
402
403 if (MF_DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED");
404
405 LED_B_ON();
406 cmd_send(CMD_ACK,isOK,0,0,0,0);
407 LED_B_OFF();
408
409
410 // Thats it...
411 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
412 LEDsoff();
413 }
414
415 /* // Command not needed but left for future testing
416 void MifareUWriteBlockCompat(uint8_t arg0, uint8_t *datain)
417 {
418 uint8_t blockNo = arg0;
419 byte_t blockdata[16] = {0x00};
420
421 memcpy(blockdata, datain, 16);
422
423 uint8_t uid[10] = {0x00};
424
425 LED_A_ON(); LED_B_OFF(); LED_C_OFF();
426
427 clear_trace();
428 iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
429
430 if(!iso14443a_select_card(uid, NULL, NULL)) {
431 if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");
432 OnError(0);
433 return;
434 };
435
436 if(mifare_ultra_writeblock_compat(blockNo, blockdata)) {
437 if (MF_DBGLEVEL >= 1) Dbprintf("Write block error");
438 OnError(0);
439 return; };
440
441 if(mifare_ultra_halt()) {
442 if (MF_DBGLEVEL >= 1) Dbprintf("Halt error");
443 OnError(0);
444 return;
445 };
446
447 if (MF_DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED");
448
449 cmd_send(CMD_ACK,1,0,0,0,0);
450 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
451 LEDsoff();
452 }
453 */
454
455 // Arg0 : Block to write to.
456 // Arg1 : 0 = use no authentication.
457 // 1 = use 0x1A authentication.
458 // 2 = use 0x1B authentication.
459 // datain : 4 first bytes is data to be written.
460 // : 4/16 next bytes is authentication key.
461 void MifareUWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain)
462 {
463 uint8_t blockNo = arg0;
464 bool useKey = (arg1 == 1); //UL_C
465 bool usePwd = (arg1 == 2); //UL_EV1/NTAG
466 byte_t blockdata[4] = {0x00};
467
468 memcpy(blockdata, datain,4);
469
470 LEDsoff();
471 LED_A_ON();
472 iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
473
474 clear_trace();
475
476 if(!iso14443a_select_card(NULL, NULL, NULL)) {
477 if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");
478 OnError(0);
479 return;
480 };
481
482 // UL-C authentication
483 if ( useKey ) {
484 uint8_t key[16] = {0x00};
485 memcpy(key, datain+4, sizeof(key) );
486
487 if ( !mifare_ultra_auth(key) ) {
488 OnError(1);
489 return;
490 }
491 }
492
493 // UL-EV1 / NTAG authentication
494 if (usePwd) {
495 uint8_t pwd[4] = {0x00};
496 memcpy(pwd, datain+4, 4);
497 uint8_t pack[4] = {0,0,0,0};
498 if (!mifare_ul_ev1_auth(pwd, pack)) {
499 OnError(1);
500 return;
501 }
502 }
503
504 if(mifare_ultra_writeblock(blockNo, blockdata)) {
505 if (MF_DBGLEVEL >= 1) Dbprintf("Write block error");
506 OnError(0);
507 return;
508 };
509
510 if(mifare_ultra_halt()) {
511 if (MF_DBGLEVEL >= 1) Dbprintf("Halt error");
512 OnError(0);
513 return;
514 };
515
516 if (MF_DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED");
517
518 cmd_send(CMD_ACK,1,0,0,0,0);
519 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
520 LEDsoff();
521 }
522
523 void MifareUSetPwd(uint8_t arg0, uint8_t *datain){
524
525 uint8_t pwd[16] = {0x00};
526 byte_t blockdata[4] = {0x00};
527
528 memcpy(pwd, datain, 16);
529
530 LED_A_ON(); LED_B_OFF(); LED_C_OFF();
531 iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
532
533 clear_trace();
534
535 if(!iso14443a_select_card(NULL, NULL, NULL)) {
536 if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");
537 OnError(0);
538 return;
539 };
540
541 blockdata[0] = pwd[7];
542 blockdata[1] = pwd[6];
543 blockdata[2] = pwd[5];
544 blockdata[3] = pwd[4];
545 if(mifare_ultra_writeblock( 44, blockdata)) {
546 if (MF_DBGLEVEL >= 1) Dbprintf("Write block error");
547 OnError(44);
548 return;
549 };
550
551 blockdata[0] = pwd[3];
552 blockdata[1] = pwd[2];
553 blockdata[2] = pwd[1];
554 blockdata[3] = pwd[0];
555 if(mifare_ultra_writeblock( 45, blockdata)) {
556 if (MF_DBGLEVEL >= 1) Dbprintf("Write block error");
557 OnError(45);
558 return;
559 };
560
561 blockdata[0] = pwd[15];
562 blockdata[1] = pwd[14];
563 blockdata[2] = pwd[13];
564 blockdata[3] = pwd[12];
565 if(mifare_ultra_writeblock( 46, blockdata)) {
566 if (MF_DBGLEVEL >= 1) Dbprintf("Write block error");
567 OnError(46);
568 return;
569 };
570
571 blockdata[0] = pwd[11];
572 blockdata[1] = pwd[10];
573 blockdata[2] = pwd[9];
574 blockdata[3] = pwd[8];
575 if(mifare_ultra_writeblock( 47, blockdata)) {
576 if (MF_DBGLEVEL >= 1) Dbprintf("Write block error");
577 OnError(47);
578 return;
579 };
580
581 if(mifare_ultra_halt()) {
582 if (MF_DBGLEVEL >= 1) Dbprintf("Halt error");
583 OnError(0);
584 return;
585 };
586
587 cmd_send(CMD_ACK,1,0,0,0,0);
588 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
589 LEDsoff();
590 }
591
592 // Return 1 if the nonce is invalid else return 0
593 int valid_nonce(uint32_t Nt, uint32_t NtEnc, uint32_t Ks1, uint8_t *parity) {
594 return ((oddparity((Nt >> 24) & 0xFF) == ((parity[0]) ^ oddparity((NtEnc >> 24) & 0xFF) ^ BIT(Ks1,16))) & \
595 (oddparity((Nt >> 16) & 0xFF) == ((parity[1]) ^ oddparity((NtEnc >> 16) & 0xFF) ^ BIT(Ks1,8))) & \
596 (oddparity((Nt >> 8) & 0xFF) == ((parity[2]) ^ oddparity((NtEnc >> 8) & 0xFF) ^ BIT(Ks1,0)))) ? 1 : 0;
597 }
598
599
600 //-----------------------------------------------------------------------------
601 // MIFARE nested authentication.
602 //
603 //-----------------------------------------------------------------------------
604 void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t calibrate, uint8_t *datain)
605 {
606 // params
607 uint8_t blockNo = arg0 & 0xff;
608 uint8_t keyType = (arg0 >> 8) & 0xff;
609 uint8_t targetBlockNo = arg1 & 0xff;
610 uint8_t targetKeyType = (arg1 >> 8) & 0xff;
611 uint64_t ui64Key = 0;
612
613 ui64Key = bytes_to_num(datain, 6);
614
615 // variables
616 uint16_t rtr, i, j, len;
617 uint16_t davg;
618 static uint16_t dmin, dmax;
619 uint8_t uid[10];
620 uint32_t cuid, nt1, nt2, nttmp, nttest, ks1;
621 uint8_t par[1];
622 uint32_t target_nt[2], target_ks[2];
623
624 uint8_t par_array[4];
625 uint16_t ncount = 0;
626 struct Crypto1State mpcs = {0, 0};
627 struct Crypto1State *pcs;
628 pcs = &mpcs;
629 uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];
630
631 uint32_t auth1_time, auth2_time;
632 static uint16_t delta_time;
633
634 LED_A_ON();
635 LED_C_OFF();
636 iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
637
638 // free eventually allocated BigBuf memory
639 BigBuf_free();
640
641 if (calibrate) clear_trace();
642 set_tracing(true);
643
644 // statistics on nonce distance
645 int16_t isOK = 0;
646 #define NESTED_MAX_TRIES 12
647 uint16_t unsuccessfull_tries = 0;
648 if (calibrate) { // for first call only. Otherwise reuse previous calibration
649 LED_B_ON();
650 WDT_HIT();
651
652 davg = dmax = 0;
653 dmin = 2000;
654 delta_time = 0;
655
656 for (rtr = 0; rtr < 17; rtr++) {
657
658 // Test if the action was cancelled
659 if(BUTTON_PRESS()) {
660 isOK = -2;
661 break;
662 }
663
664 // prepare next select. No need to power down the card.
665 if(mifare_classic_halt(pcs, cuid)) {
666 if (MF_DBGLEVEL >= 1) Dbprintf("Nested: Halt error");
667 rtr--;
668 continue;
669 }
670
671 if(!iso14443a_select_card(uid, NULL, &cuid)) {
672 if (MF_DBGLEVEL >= 1) Dbprintf("Nested: Can't select card");
673 rtr--;
674 continue;
675 };
676
677 auth1_time = 0;
678 if(mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST, &nt1, &auth1_time)) {
679 if (MF_DBGLEVEL >= 1) Dbprintf("Nested: Auth1 error");
680 rtr--;
681 continue;
682 };
683
684 if (delta_time) {
685 auth2_time = auth1_time + delta_time;
686 } else {
687 auth2_time = 0;
688 }
689 if(mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_NESTED, &nt2, &auth2_time)) {
690 if (MF_DBGLEVEL >= 1) Dbprintf("Nested: Auth2 error");
691 rtr--;
692 continue;
693 };
694
695 nttmp = prng_successor(nt1, 100); //NXP Mifare is typical around 840,but for some unlicensed/compatible mifare card this can be 160
696 for (i = 101; i < 1200; i++) {
697 nttmp = prng_successor(nttmp, 1);
698 if (nttmp == nt2) break;
699 }
700
701 if (i != 1200) {
702 if (rtr != 0) {
703 davg += i;
704 dmin = MIN(dmin, i);
705 dmax = MAX(dmax, i);
706 }
707 else {
708 delta_time = auth2_time - auth1_time + 32; // allow some slack for proper timing
709 }
710 if (MF_DBGLEVEL >= 3) Dbprintf("Nested: calibrating... ntdist=%d", i);
711 } else {
712 unsuccessfull_tries++;
713 if (unsuccessfull_tries > NESTED_MAX_TRIES) { // card isn't vulnerable to nested attack (random numbers are not predictable)
714 isOK = -3;
715 }
716 }
717 }
718
719 davg = (davg + (rtr - 1)/2) / (rtr - 1);
720
721 if (MF_DBGLEVEL >= 3) Dbprintf("rtr=%d isOK=%d min=%d max=%d avg=%d, delta_time=%d", rtr, isOK, dmin, dmax, davg, delta_time);
722
723 dmin = davg - 2;
724 dmax = davg + 2;
725
726 LED_B_OFF();
727 }
728 // -------------------------------------------------------------------------------------------------
729
730 LED_C_ON();
731
732 // get crypted nonces for target sector
733 for(i=0; i < 2 && !isOK; i++) { // look for exactly two different nonces
734
735 target_nt[i] = 0;
736 while(target_nt[i] == 0) { // continue until we have an unambiguous nonce
737
738 // prepare next select. No need to power down the card.
739 if(mifare_classic_halt(pcs, cuid)) {
740 if (MF_DBGLEVEL >= 1) Dbprintf("Nested: Halt error");
741 continue;
742 }
743
744 if(!iso14443a_select_card(uid, NULL, &cuid)) {
745 if (MF_DBGLEVEL >= 1) Dbprintf("Nested: Can't select card");
746 continue;
747 };
748
749 auth1_time = 0;
750 if(mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST, &nt1, &auth1_time)) {
751 if (MF_DBGLEVEL >= 1) Dbprintf("Nested: Auth1 error");
752 continue;
753 };
754
755 // nested authentication
756 auth2_time = auth1_time + delta_time;
757 len = mifare_sendcmd_short(pcs, AUTH_NESTED, 0x60 + (targetKeyType & 0x01), targetBlockNo, receivedAnswer, par, &auth2_time);
758 if (len != 4) {
759 if (MF_DBGLEVEL >= 1) Dbprintf("Nested: Auth2 error len=%d", len);
760 continue;
761 };
762
763 nt2 = bytes_to_num(receivedAnswer, 4);
764 if (MF_DBGLEVEL >= 3) Dbprintf("Nonce#%d: Testing nt1=%08x nt2enc=%08x nt2par=%02x", i+1, nt1, nt2, par[0]);
765
766 // Parity validity check
767 for (j = 0; j < 4; j++) {
768 par_array[j] = (oddparity(receivedAnswer[j]) != ((par[0] >> (7-j)) & 0x01));
769 }
770
771 ncount = 0;
772 nttest = prng_successor(nt1, dmin - 1);
773 for (j = dmin; j < dmax + 1; j++) {
774 nttest = prng_successor(nttest, 1);
775 ks1 = nt2 ^ nttest;
776
777 if (valid_nonce(nttest, nt2, ks1, par_array)){
778 if (ncount > 0) { // we are only interested in disambiguous nonces, try again
779 if (MF_DBGLEVEL >= 3) Dbprintf("Nonce#%d: dismissed (ambigous), ntdist=%d", i+1, j);
780 target_nt[i] = 0;
781 break;
782 }
783 target_nt[i] = nttest;
784 target_ks[i] = ks1;
785 ncount++;
786 if (i == 1 && target_nt[1] == target_nt[0]) { // we need two different nonces
787 target_nt[i] = 0;
788 if (MF_DBGLEVEL >= 3) Dbprintf("Nonce#2: dismissed (= nonce#1), ntdist=%d", j);
789 break;
790 }
791 if (MF_DBGLEVEL >= 3) Dbprintf("Nonce#%d: valid, ntdist=%d", i+1, j);
792 }
793 }
794 if (target_nt[i] == 0 && j == dmax+1 && MF_DBGLEVEL >= 3) Dbprintf("Nonce#%d: dismissed (all invalid)", i+1);
795 }
796 }
797
798 LED_C_OFF();
799
800 // ----------------------------- crypto1 destroy
801 crypto1_destroy(pcs);
802
803 byte_t buf[4 + 4 * 4];
804 memcpy(buf, &cuid, 4);
805 memcpy(buf+4, &target_nt[0], 4);
806 memcpy(buf+8, &target_ks[0], 4);
807 memcpy(buf+12, &target_nt[1], 4);
808 memcpy(buf+16, &target_ks[1], 4);
809
810 LED_B_ON();
811 cmd_send(CMD_ACK, isOK, 0, targetBlockNo + (targetKeyType * 0x100), buf, sizeof(buf));
812 LED_B_OFF();
813
814 if (MF_DBGLEVEL >= 3) DbpString("NESTED FINISHED");
815
816 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
817 LEDsoff();
818 set_tracing(FALSE);
819 }
820
821 //-----------------------------------------------------------------------------
822 // MIFARE check keys. key count up to 85.
823 //
824 //-----------------------------------------------------------------------------
825 void MifareChkKeys(uint16_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
826 {
827 // params
828 uint8_t blockNo = arg0 & 0xff;
829 uint8_t keyType = (arg0 >> 8) & 0xff;
830 bool clearTrace = arg1;
831 uint8_t keyCount = arg2;
832 uint64_t ui64Key = 0;
833
834 // variables
835 int i;
836 byte_t isOK = 0;
837 uint8_t uid[10];
838 uint32_t cuid;
839 struct Crypto1State mpcs = {0, 0};
840 struct Crypto1State *pcs;
841 pcs = &mpcs;
842
843 // clear debug level
844 int OLD_MF_DBGLEVEL = MF_DBGLEVEL;
845 MF_DBGLEVEL = MF_DBG_NONE;
846
847 LED_A_ON();
848 LED_B_OFF();
849 LED_C_OFF();
850 iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
851
852 if (clearTrace) clear_trace();
853 set_tracing(TRUE);
854
855 for (i = 0; i < keyCount; i++) {
856 if(mifare_classic_halt(pcs, cuid)) {
857 if (MF_DBGLEVEL >= 1) Dbprintf("ChkKeys: Halt error");
858 }
859
860 if(!iso14443a_select_card(uid, NULL, &cuid)) {
861 if (OLD_MF_DBGLEVEL >= 1) Dbprintf("ChkKeys: Can't select card");
862 break;
863 };
864
865 ui64Key = bytes_to_num(datain + i * 6, 6);
866 if(mifare_classic_auth(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST)) {
867 continue;
868 };
869
870 isOK = 1;
871 break;
872 }
873
874 // ----------------------------- crypto1 destroy
875 crypto1_destroy(pcs);
876
877 LED_B_ON();
878 cmd_send(CMD_ACK,isOK,0,0,datain + i * 6,6);
879 LED_B_OFF();
880
881 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
882 LEDsoff();
883 set_tracing(FALSE);
884
885 // restore debug level
886 MF_DBGLEVEL = OLD_MF_DBGLEVEL;
887 }
888
889 //-----------------------------------------------------------------------------
890 // MIFARE commands set debug level
891 //
892 //-----------------------------------------------------------------------------
893 void MifareSetDbgLvl(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){
894 MF_DBGLEVEL = arg0;
895 Dbprintf("Debug level: %d", MF_DBGLEVEL);
896 }
897
898 //-----------------------------------------------------------------------------
899 // Work with emulator memory
900 //
901 // Note: we call FpgaDownloadAndGo(FPGA_BITSTREAM_HF) here although FPGA is not
902 // involved in dealing with emulator memory. But if it is called later, it might
903 // destroy the Emulator Memory.
904 //-----------------------------------------------------------------------------
905
906 void MifareEMemClr(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){
907 FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
908 emlClearMem();
909 }
910
911 void MifareEMemSet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){
912 FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
913 //emlSetMem(datain, arg0, arg1); // data, block num, blocks count
914 emlSetMem_xt(datain, arg0, arg1, arg2); // data, block num, blocks count, block byte width
915 }
916
917 void MifareEMemGet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){
918 FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
919 byte_t buf[USB_CMD_DATA_SIZE];
920 emlGetMem(buf, arg0, arg1); // data, block num, blocks count (max 4)
921
922 LED_B_ON();
923 cmd_send(CMD_ACK,arg0,arg1,0,buf,USB_CMD_DATA_SIZE);
924 LED_B_OFF();
925 }
926
927 //-----------------------------------------------------------------------------
928 // Load a card into the emulator memory
929 //
930 //-----------------------------------------------------------------------------
931 void MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){
932 uint8_t numSectors = arg0;
933 uint8_t keyType = arg1;
934 uint64_t ui64Key = 0;
935 uint32_t cuid;
936 struct Crypto1State mpcs = {0, 0};
937 struct Crypto1State *pcs;
938 pcs = &mpcs;
939
940 // variables
941 byte_t dataoutbuf[16];
942 byte_t dataoutbuf2[16];
943 uint8_t uid[10];
944
945 LED_A_ON();
946 LED_B_OFF();
947 LED_C_OFF();
948 iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
949
950 clear_trace();
951 set_tracing(TRUE);
952
953 bool isOK = true;
954
955 if(!iso14443a_select_card(uid, NULL, &cuid)) {
956 isOK = false;
957 if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");
958 }
959
960 for (uint8_t sectorNo = 0; isOK && sectorNo < numSectors; sectorNo++) {
961 ui64Key = emlGetKey(sectorNo, keyType);
962 if (sectorNo == 0){
963 if(isOK && mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keyType, ui64Key, AUTH_FIRST)) {
964 isOK = false;
965 if (MF_DBGLEVEL >= 1) Dbprintf("Sector[%2d]. Auth error", sectorNo);
966 break;
967 }
968 } else {
969 if(isOK && mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keyType, ui64Key, AUTH_NESTED)) {
970 isOK = false;
971 if (MF_DBGLEVEL >= 1) Dbprintf("Sector[%2d]. Auth nested error", sectorNo);
972 break;
973 }
974 }
975
976 for (uint8_t blockNo = 0; isOK && blockNo < NumBlocksPerSector(sectorNo); blockNo++) {
977 if(isOK && mifare_classic_readblock(pcs, cuid, FirstBlockOfSector(sectorNo) + blockNo, dataoutbuf)) {
978 isOK = false;
979 if (MF_DBGLEVEL >= 1) Dbprintf("Error reading sector %2d block %2d", sectorNo, blockNo);
980 break;
981 };
982 if (isOK) {
983 if (blockNo < NumBlocksPerSector(sectorNo) - 1) {
984 emlSetMem(dataoutbuf, FirstBlockOfSector(sectorNo) + blockNo, 1);
985 } else { // sector trailer, keep the keys, set only the AC
986 emlGetMem(dataoutbuf2, FirstBlockOfSector(sectorNo) + blockNo, 1);
987 memcpy(&dataoutbuf2[6], &dataoutbuf[6], 4);
988 emlSetMem(dataoutbuf2, FirstBlockOfSector(sectorNo) + blockNo, 1);
989 }
990 }
991 }
992
993 }
994
995 if(mifare_classic_halt(pcs, cuid)) {
996 if (MF_DBGLEVEL >= 1) Dbprintf("Halt error");
997 };
998
999 // ----------------------------- crypto1 destroy
1000 crypto1_destroy(pcs);
1001
1002 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
1003 LEDsoff();
1004
1005 if (MF_DBGLEVEL >= 2) DbpString("EMUL FILL SECTORS FINISHED");
1006
1007 set_tracing(FALSE);
1008 }
1009
1010
1011 //-----------------------------------------------------------------------------
1012 // Work with "magic Chinese" card (email him: ouyangweidaxian@live.cn)
1013 //
1014 // PARAMS - workFlags
1015 // bit 0 - need get UID
1016 // bit 1 - need wupC
1017 // bit 2 - need HALT after sequence
1018 // bit 3 - need turn on FPGA before sequence
1019 // bit 4 - need turn off FPGA
1020 // bit 5 - need to set datain instead of issuing USB reply (called via ARM for StandAloneMode14a)
1021 // bit 6 - wipe tag.
1022 //-----------------------------------------------------------------------------
1023 // magic uid card generation 1 commands
1024 uint8_t wupC1[] = { MIFARE_MAGICWUPC1 };
1025 uint8_t wupC2[] = { MIFARE_MAGICWUPC2 };
1026 uint8_t wipeC[] = { MIFARE_MAGICWIPEC };
1027
1028 void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain){
1029
1030 // params
1031 uint8_t workFlags = arg0;
1032 uint8_t blockNo = arg1;
1033
1034 Dbprintf("ICE :: CSetBlocks Flags %02x", workFlags);
1035
1036 // variables
1037 uint8_t uid[10] = {0x00};
1038 uint8_t data[18] = {0x00};
1039 uint32_t cuid;
1040
1041 uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];
1042 uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];
1043
1044 if (workFlags & MAGIC_INIT) {
1045 LED_A_ON();
1046 LED_B_OFF();
1047 iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
1048 clear_trace();
1049 set_tracing(TRUE);
1050 }
1051
1052 // read UID and return to client
1053 if (workFlags & MAGIC_UID) {
1054 if(!iso14443a_select_card(uid, NULL, &cuid)) {
1055 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Can't select card");
1056 OnErrorMagic(MAGIC_UID);
1057 };
1058 };
1059
1060 // wipe tag, fill it with zeros
1061 if (workFlags & MAGIC_WIPE){
1062 ReaderTransmitBitsPar(wupC1,7,0, NULL);
1063 if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
1064 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("wupC1 error");
1065 OnErrorMagic(MAGIC_WIPE);
1066 };
1067
1068 ReaderTransmit(wipeC, sizeof(wipeC), NULL);
1069 if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
1070 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("wipeC error");
1071 OnErrorMagic(MAGIC_WIPE);
1072 };
1073 };
1074
1075 // write block
1076 if (workFlags & MAGIC_WUPC) {
1077 ReaderTransmitBitsPar(wupC1,7,0, NULL);
1078 if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
1079 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("wupC1 error");
1080 OnErrorMagic(MAGIC_WUPC);
1081 };
1082
1083 ReaderTransmit(wupC2, sizeof(wupC2), NULL);
1084 if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
1085 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("wupC2 error");
1086 OnErrorMagic(MAGIC_WUPC);
1087 };
1088 }
1089
1090 if ((mifare_sendcmd_short(NULL, 0, ISO14443A_CMD_WRITEBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL) != 1) || (receivedAnswer[0] != 0x0a)) {
1091 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("write block send command error");
1092 OnErrorMagic(4);
1093 };
1094
1095 memcpy(data, datain, 16);
1096 AppendCrc14443a(data, 16);
1097
1098 ReaderTransmit(data, sizeof(data), NULL);
1099 if ((ReaderReceive(receivedAnswer, receivedAnswerPar) != 1) || (receivedAnswer[0] != 0x0a)) {
1100 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("write block send data error");
1101 OnErrorMagic(0);
1102 };
1103
1104 if (workFlags & MAGIC_OFF)
1105 mifare_classic_halt_ex(NULL);
1106
1107 LED_B_ON();
1108 // check if uid is cuid?
1109 cmd_send(CMD_ACK,1,0,0,uid,sizeof(uid));
1110 LED_B_OFF();
1111
1112 if (workFlags & MAGIC_OFF)
1113 OnSuccessMagic();
1114 }
1115
1116 void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain){
1117
1118 uint8_t workFlags = arg0;
1119 uint8_t blockNo = arg1;
1120
1121 // variables
1122 uint8_t data[MAX_MIFARE_FRAME_SIZE];
1123 uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];
1124 uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];
1125
1126 memset(data, 0x00, sizeof(data));
1127
1128 if (workFlags & MAGIC_INIT) {
1129 LED_A_ON();
1130 LED_B_OFF();
1131 iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
1132 clear_trace();
1133 set_tracing(TRUE);
1134 }
1135
1136 if (workFlags & MAGIC_WUPC) {
1137 ReaderTransmitBitsPar(wupC1,7,0, NULL);
1138 if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
1139 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("wupC1 error");
1140 OnErrorMagic(MAGIC_WUPC);
1141 };
1142
1143 ReaderTransmit(wupC2, sizeof(wupC2), NULL);
1144 if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
1145 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("wupC2 error");
1146 OnErrorMagic(MAGIC_WUPC);
1147 };
1148 }
1149
1150 // read block
1151 if ((mifare_sendcmd_short(NULL, 0, ISO14443A_CMD_READBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL) != 18)) {
1152 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("read block send command error");
1153 OnErrorMagic(0);
1154 };
1155
1156 memcpy(data, receivedAnswer, sizeof(data));
1157
1158 // send HALT
1159 if (workFlags & MAGIC_HALT)
1160 mifare_classic_halt_ex(NULL);
1161
1162 LED_B_ON();
1163
1164 // if MAGIC_DATAIN, the data stays on device side.
1165 if (workFlags & MAGIC_DATAIN)
1166 memcpy(datain, data, sizeof(data));
1167 else
1168 cmd_send(CMD_ACK,1,0,0,data,sizeof(data));
1169
1170 LED_B_OFF();
1171
1172 if (workFlags & MAGIC_OFF)
1173 OnSuccessMagic();
1174 }
1175
1176 void MifareCIdent(){
1177
1178 // variables
1179 byte_t isOK = 1;
1180 uint8_t receivedAnswer[1];
1181 uint8_t receivedAnswerPar[1];
1182
1183 ReaderTransmitBitsPar(wupC1,7,0, NULL);
1184 if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
1185 isOK = 0;
1186 };
1187
1188 ReaderTransmit(wupC2, sizeof(wupC2), NULL);
1189 if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
1190 isOK = 0;
1191 };
1192
1193 // removed the if, since some magic tags misbehavies and send an answer to it.
1194 mifare_classic_halt(NULL, 0);
1195 cmd_send(CMD_ACK,isOK,0,0,0,0);
1196 }
1197
1198 void OnSuccessMagic(){
1199 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
1200 LEDsoff();
1201 set_tracing(FALSE);
1202 }
1203 void OnErrorMagic(uint8_t reason){
1204 // ACK, ISOK, reason,0,0,0
1205 cmd_send(CMD_ACK,0,reason,0,0,0);
1206 OnSuccessMagic();
1207 }
1208
1209 void MifareCollectNonces(uint32_t arg0, uint32_t arg1){
1210 }
1211
1212 //
1213 // DESFIRE
1214 //
1215
1216 void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain){
1217
1218 byte_t dataout[11] = {0x00};
1219 uint8_t uid[10] = {0x00};
1220 uint32_t cuid = 0x00;
1221
1222 iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
1223 clear_trace();
1224
1225 int len = iso14443a_select_card(uid, NULL, &cuid);
1226 if(!len) {
1227 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Can't select card");
1228 OnError(1);
1229 return;
1230 };
1231
1232 if(mifare_desfire_des_auth1(cuid, dataout)){
1233 if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Authentication part1: Fail.");
1234 OnError(4);
1235 return;
1236 }
1237
1238 if (MF_DBGLEVEL >= MF_DBG_EXTENDED) DbpString("AUTH 1 FINISHED");
1239 cmd_send(CMD_ACK,1,cuid,0,dataout, sizeof(dataout));
1240 }
1241
1242 void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain){
1243
1244 uint32_t cuid = arg0;
1245 uint8_t key[16] = {0x00};
1246 byte_t dataout[12] = {0x00};
1247 byte_t isOK = 0;
1248
1249 memcpy(key, datain, 16);
1250
1251 isOK = mifare_desfire_des_auth2(cuid, key, dataout);
1252
1253 if( isOK) {
1254 if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Authentication part2: Failed");
1255 OnError(4);
1256 return;
1257 }
1258
1259 if (MF_DBGLEVEL >= MF_DBG_EXTENDED) DbpString("AUTH 2 FINISHED");
1260
1261 cmd_send(CMD_ACK, isOK, 0, 0, dataout, sizeof(dataout));
1262 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
1263 LEDsoff();
1264 }
Impressum, Datenschutz