Skip to content

Commit 44964fd

Browse files
authored
Code cleanup (#616)
* coverity fixes (including a real bug in cmdhftopaz.c) * Typo fix * replace TRUE/FALSE by stdbool true/false
1 parent 2bb7f7e commit 44964fd

30 files changed

+198
-212
lines changed

armsrc/appmain.c

+53-59
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ void StandAloneMode14a()
394394
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
395395

396396
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};
399399
uint8_t readUID[10] = {0};
400400
uint32_t uid_1st[OPTS]={0};
401401
uint32_t uid_2nd[OPTS]={0};
@@ -411,9 +411,9 @@ void StandAloneMode14a()
411411
WDT_HIT();
412412
SpinDelay(300);
413413

414-
if (iGotoRecord == 1 || cardRead[selected] == 0)
414+
if (GotoRecord || !cardRead[selected])
415415
{
416-
iGotoRecord = 0;
416+
GotoRecord = false;
417417
LEDsoff();
418418
LED(selected + 1, 0);
419419
LED(LED_RED2, 0);
@@ -438,7 +438,7 @@ void StandAloneMode14a()
438438
else if (cardRead[(selected+1)%OPTS]) {
439439
Dbprintf("Button press detected but no card in bank[%d] so playing from bank[%d]", selected, (selected+1)%OPTS);
440440
selected = (selected+1)%OPTS;
441-
break; // playing = 1;
441+
break;
442442
}
443443
else {
444444
Dbprintf("Button press detected but no stored tag to play. (Ignoring button)");
@@ -488,14 +488,14 @@ void StandAloneMode14a()
488488
LED(selected + 1, 0);
489489

490490
// Next state is replay:
491-
playing = 1;
491+
playing = true;
492492

493-
cardRead[selected] = 1;
493+
cardRead[selected] = true;
494494
}
495495
/* MF Classic UID clone */
496-
else if (iGotoClone==1)
496+
else if (GotoClone)
497497
{
498-
iGotoClone=0;
498+
GotoClone=false;
499499
LEDsoff();
500500
LED(selected + 1, 0);
501501
LED(LED_ORANGE, 250);
@@ -546,7 +546,7 @@ void StandAloneMode14a()
546546
MifareCGetBlock(0x3F, 1, 0, oldBlock0);
547547
if (oldBlock0[0] == 0 && oldBlock0[0] == oldBlock0[1] && oldBlock0[1] == oldBlock0[2] && oldBlock0[2] == oldBlock0[3]) {
548548
Dbprintf("No changeable tag detected. Returning to replay mode for bank[%d]", selected);
549-
playing = 1;
549+
playing = true;
550550
}
551551
else {
552552
Dbprintf("UID from target tag: %02X%02X%02X%02X", oldBlock0[0],oldBlock0[1],oldBlock0[2],oldBlock0[3]);
@@ -564,76 +564,70 @@ void StandAloneMode14a()
564564
if (memcmp(testBlock0,newBlock0,16)==0)
565565
{
566566
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;
570570
selected = (selected+1) % OPTS;
571571
}
572572
else {
573573
Dbprintf("Clone failed. Back to replay mode on bank[%d]", selected);
574-
playing = 1;
574+
playing = true;
575575
}
576576
}
577577
LEDsoff();
578578
LED(selected + 1, 0);
579579

580580
}
581581
// 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])
583583
{
584584
LEDsoff();
585585
LED(selected + 1, 0);
586586

587587
// 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
614599
}
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
620603
}
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);
625611
}
626-
WDT_HIT();
627612
}
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();
633625
}
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);
637631
}
638632
}
639633
}

armsrc/hitag2.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -813,13 +813,13 @@ void SnoopHitag(uint32_t type) {
813813
int lastbit;
814814
bool bSkip;
815815
int tag_sof;
816-
byte_t rx[HITAG_FRAME_LEN];
816+
byte_t rx[HITAG_FRAME_LEN] = {0};
817817
size_t rxlen=0;
818818

819819
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
820820

821821
// Clean up trace and prepare it for storing frames
822-
set_tracing(TRUE);
822+
set_tracing(true);
823823
clear_trace();
824824

825825
auth_table_len = 0;
@@ -1032,7 +1032,7 @@ void SimulateHitagTag(bool tag_mem_supplied, byte_t* data) {
10321032
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
10331033

10341034
// Clean up trace and prepare it for storing frames
1035-
set_tracing(TRUE);
1035+
set_tracing(true);
10361036
clear_trace();
10371037

10381038
auth_table_len = 0;
@@ -1225,7 +1225,7 @@ void ReaderHitag(hitag_function htf, hitag_data* htd) {
12251225
bSuccessful = false;
12261226

12271227
// Clean up trace and prepare it for storing frames
1228-
set_tracing(TRUE);
1228+
set_tracing(true);
12291229
clear_trace();
12301230

12311231
//DbpString("Starting Hitag reader family");
@@ -1548,7 +1548,7 @@ void WriterHitag(hitag_function htf, hitag_data* htd, int page) {
15481548
bSuccessful = false;
15491549

15501550
// Clean up trace and prepare it for storing frames
1551-
set_tracing(TRUE);
1551+
set_tracing(true);
15521552
clear_trace();
15531553

15541554
//DbpString("Starting Hitag reader family");

armsrc/hitagS.c

+5-6
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static void hitag_send_bit(int bit) {
210210
;
211211
LOW(GPIO_SSC_DOUT);
212212
while (AT91C_BASE_TC0->TC_CV < T0 * 32)
213-
;;
213+
;
214214
}
215215
LED_A_OFF();
216216
break;
@@ -945,15 +945,14 @@ void SimulateHitagSTag(bool tag_mem_supplied, byte_t* data) {
945945
int i, j;
946946
byte_t rx[HITAG_FRAME_LEN];
947947
size_t rxlen = 0;
948-
//bool bQuitTraceFull = false;
949948
bQuiet = false;
950949
byte_t txbuf[HITAG_FRAME_LEN];
951950
byte_t* tx = txbuf;
952951
size_t txlen = 0;
953952
BigBuf_free();
954953

955954
// Clean up trace and prepare it for storing frames
956-
set_tracing(TRUE);
955+
set_tracing(true);
957956
clear_trace();
958957

959958
DbpString("Starting HitagS simulation");
@@ -1216,7 +1215,7 @@ void ReadHitagS(hitag_function htf, hitag_data* htd) {
12161215
bSuccessful = false;
12171216

12181217
// Clean up trace and prepare it for storing frames
1219-
set_tracing(TRUE);
1218+
set_tracing(true);
12201219
clear_trace();
12211220

12221221
bQuiet = false;
@@ -1560,7 +1559,7 @@ void WritePageHitagS(hitag_function htf, hitag_data* htd,int page_) {
15601559
tag.tstate = NO_OP;
15611560

15621561
// Clean up trace and prepare it for storing frames
1563-
set_tracing(TRUE);
1562+
set_tracing(true);
15641563
clear_trace();
15651564

15661565
bQuiet = false;
@@ -1847,7 +1846,7 @@ void check_challenges(bool file_given, byte_t* data) {
18471846
bSuccessful = false;
18481847

18491848
// Clean up trace and prepare it for storing frames
1850-
set_tracing(TRUE);
1849+
set_tracing(true);
18511850
clear_trace();
18521851

18531852
bQuiet = false;

0 commit comments

Comments
 (0)