@@ -394,8 +394,8 @@ void StandAloneMode14a()
394
394
FpgaDownloadAndGo (FPGA_BITSTREAM_HF );
395
395
396
396
int selected = 0 ;
397
- int playing = 0 , iGotoRecord = 0 , iGotoClone = 0 ;
398
- int cardRead [OPTS ] = {0 };
397
+ bool playing = false, GotoRecord = false, GotoClone = false ;
398
+ bool cardRead [OPTS ] = {false };
399
399
uint8_t readUID [10 ] = {0 };
400
400
uint32_t uid_1st [OPTS ]= {0 };
401
401
uint32_t uid_2nd [OPTS ]= {0 };
@@ -411,9 +411,9 @@ void StandAloneMode14a()
411
411
WDT_HIT ();
412
412
SpinDelay (300 );
413
413
414
- if (iGotoRecord == 1 || cardRead [selected ] == 0 )
414
+ if (GotoRecord || ! cardRead [selected ])
415
415
{
416
- iGotoRecord = 0 ;
416
+ GotoRecord = false ;
417
417
LEDsoff ();
418
418
LED (selected + 1 , 0 );
419
419
LED (LED_RED2 , 0 );
@@ -438,7 +438,7 @@ void StandAloneMode14a()
438
438
else if (cardRead [(selected + 1 )%OPTS ]) {
439
439
Dbprintf ("Button press detected but no card in bank[%d] so playing from bank[%d]" , selected , (selected + 1 )%OPTS );
440
440
selected = (selected + 1 )%OPTS ;
441
- break ; // playing = 1;
441
+ break ;
442
442
}
443
443
else {
444
444
Dbprintf ("Button press detected but no stored tag to play. (Ignoring button)" );
@@ -488,14 +488,14 @@ void StandAloneMode14a()
488
488
LED (selected + 1 , 0 );
489
489
490
490
// Next state is replay:
491
- playing = 1 ;
491
+ playing = true ;
492
492
493
- cardRead [selected ] = 1 ;
493
+ cardRead [selected ] = true ;
494
494
}
495
495
/* MF Classic UID clone */
496
- else if (iGotoClone == 1 )
496
+ else if (GotoClone )
497
497
{
498
- iGotoClone = 0 ;
498
+ GotoClone = false ;
499
499
LEDsoff ();
500
500
LED (selected + 1 , 0 );
501
501
LED (LED_ORANGE , 250 );
@@ -546,7 +546,7 @@ void StandAloneMode14a()
546
546
MifareCGetBlock (0x3F , 1 , 0 , oldBlock0 );
547
547
if (oldBlock0 [0 ] == 0 && oldBlock0 [0 ] == oldBlock0 [1 ] && oldBlock0 [1 ] == oldBlock0 [2 ] && oldBlock0 [2 ] == oldBlock0 [3 ]) {
548
548
Dbprintf ("No changeable tag detected. Returning to replay mode for bank[%d]" , selected );
549
- playing = 1 ;
549
+ playing = true ;
550
550
}
551
551
else {
552
552
Dbprintf ("UID from target tag: %02X%02X%02X%02X" , oldBlock0 [0 ],oldBlock0 [1 ],oldBlock0 [2 ],oldBlock0 [3 ]);
@@ -564,76 +564,70 @@ void StandAloneMode14a()
564
564
if (memcmp (testBlock0 ,newBlock0 ,16 )== 0 )
565
565
{
566
566
DbpString ("Cloned successfull!" );
567
- cardRead [selected ] = 0 ; // Only if the card was cloned successfully should we clear it
568
- playing = 0 ;
569
- iGotoRecord = 1 ;
567
+ cardRead [selected ] = false ; // Only if the card was cloned successfully should we clear it
568
+ playing = false ;
569
+ GotoRecord = true ;
570
570
selected = (selected + 1 ) % OPTS ;
571
571
}
572
572
else {
573
573
Dbprintf ("Clone failed. Back to replay mode on bank[%d]" , selected );
574
- playing = 1 ;
574
+ playing = true ;
575
575
}
576
576
}
577
577
LEDsoff ();
578
578
LED (selected + 1 , 0 );
579
579
580
580
}
581
581
// Change where to record (or begin playing)
582
- else if (playing == 1 ) // button_pressed == BUTTON_SINGLE_CLICK && cardRead[selected])
582
+ else if (playing ) // button_pressed == BUTTON_SINGLE_CLICK && cardRead[selected])
583
583
{
584
584
LEDsoff ();
585
585
LED (selected + 1 , 0 );
586
586
587
587
// Begin transmitting
588
- if (playing )
589
- {
590
- LED (LED_GREEN , 0 );
591
- DbpString ("Playing" );
592
- for ( ; ; ) {
593
- WDT_HIT ();
594
- int button_action = BUTTON_HELD (1000 );
595
- if (button_action == 0 ) { // No button action, proceed with sim
596
- uint8_t data [512 ] = {0 }; // in case there is a read command received we shouldn't break
597
- Dbprintf ("Simulating ISO14443a tag with uid[0]: %08x, uid[1]: %08x [Bank: %u]" , uid_1st [selected ],uid_2nd [selected ],selected );
598
- if (hi14a_card [selected ].sak == 8 && hi14a_card [selected ].atqa [0 ] == 4 && hi14a_card [selected ].atqa [1 ] == 0 ) {
599
- DbpString ("Mifare Classic" );
600
- SimulateIso14443aTag (1 ,uid_1st [selected ], uid_2nd [selected ], data ); // Mifare Classic
601
- }
602
- else if (hi14a_card [selected ].sak == 0 && hi14a_card [selected ].atqa [0 ] == 0x44 && hi14a_card [selected ].atqa [1 ] == 0 ) {
603
- DbpString ("Mifare Ultralight" );
604
- SimulateIso14443aTag (2 ,uid_1st [selected ],uid_2nd [selected ],data ); // Mifare Ultralight
605
- }
606
- else if (hi14a_card [selected ].sak == 20 && hi14a_card [selected ].atqa [0 ] == 0x44 && hi14a_card [selected ].atqa [1 ] == 3 ) {
607
- DbpString ("Mifare DESFire" );
608
- SimulateIso14443aTag (3 ,uid_1st [selected ],uid_2nd [selected ],data ); // Mifare DESFire
609
- }
610
- else {
611
- Dbprintf ("Unrecognized tag type -- defaulting to Mifare Classic emulation" );
612
- SimulateIso14443aTag (1 ,uid_1st [selected ], uid_2nd [selected ], data );
613
- }
588
+ LED (LED_GREEN , 0 );
589
+ DbpString ("Playing" );
590
+ for ( ; ; ) {
591
+ WDT_HIT ();
592
+ int button_action = BUTTON_HELD (1000 );
593
+ if (button_action == 0 ) { // No button action, proceed with sim
594
+ uint8_t data [512 ] = {0 }; // in case there is a read command received we shouldn't break
595
+ Dbprintf ("Simulating ISO14443a tag with uid[0]: %08x, uid[1]: %08x [Bank: %u]" , uid_1st [selected ],uid_2nd [selected ],selected );
596
+ if (hi14a_card [selected ].sak == 8 && hi14a_card [selected ].atqa [0 ] == 4 && hi14a_card [selected ].atqa [1 ] == 0 ) {
597
+ DbpString ("Mifare Classic" );
598
+ SimulateIso14443aTag (1 ,uid_1st [selected ], uid_2nd [selected ], data ); // Mifare Classic
614
599
}
615
- else if (button_action == BUTTON_SINGLE_CLICK ) {
616
- selected = (selected + 1 ) % OPTS ;
617
- Dbprintf ("Done playing. Switching to record mode on bank %d" ,selected );
618
- iGotoRecord = 1 ;
619
- break ;
600
+ else if (hi14a_card [selected ].sak == 0 && hi14a_card [selected ].atqa [0 ] == 0x44 && hi14a_card [selected ].atqa [1 ] == 0 ) {
601
+ DbpString ("Mifare Ultralight" );
602
+ SimulateIso14443aTag (2 ,uid_1st [selected ],uid_2nd [selected ],data ); // Mifare Ultralight
620
603
}
621
- else if (button_action == BUTTON_HOLD ) {
622
- Dbprintf ("Playtime over. Begin cloning..." );
623
- iGotoClone = 1 ;
624
- break ;
604
+ else if (hi14a_card [selected ].sak == 20 && hi14a_card [selected ].atqa [0 ] == 0x44 && hi14a_card [selected ].atqa [1 ] == 3 ) {
605
+ DbpString ("Mifare DESFire" );
606
+ SimulateIso14443aTag (3 ,uid_1st [selected ],uid_2nd [selected ],data ); // Mifare DESFire
607
+ }
608
+ else {
609
+ Dbprintf ("Unrecognized tag type -- defaulting to Mifare Classic emulation" );
610
+ SimulateIso14443aTag (1 ,uid_1st [selected ], uid_2nd [selected ], data );
625
611
}
626
- WDT_HIT ();
627
612
}
628
-
629
- /* We pressed a button so ignore it here with a delay */
630
- SpinDelay (300 );
631
- LEDsoff ();
632
- LED (selected + 1 , 0 );
613
+ else if (button_action == BUTTON_SINGLE_CLICK ) {
614
+ selected = (selected + 1 ) % OPTS ;
615
+ Dbprintf ("Done playing. Switching to record mode on bank %d" ,selected );
616
+ GotoRecord = true;
617
+ break ;
618
+ }
619
+ else if (button_action == BUTTON_HOLD ) {
620
+ Dbprintf ("Playtime over. Begin cloning..." );
621
+ GotoClone = true;
622
+ break ;
623
+ }
624
+ WDT_HIT ();
633
625
}
634
- else
635
- while (BUTTON_PRESS ())
636
- WDT_HIT ();
626
+
627
+ /* We pressed a button so ignore it here with a delay */
628
+ SpinDelay (300 );
629
+ LEDsoff ();
630
+ LED (selected + 1 , 0 );
637
631
}
638
632
}
639
633
}
0 commit comments