Skip to content

Commit 45d869e

Browse files
committed
change "mem wipe" / "mem info" to use NG.\nsome more style changes
1 parent af9567a commit 45d869e

File tree

6 files changed

+101
-73
lines changed

6 files changed

+101
-73
lines changed

armsrc/appmain.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,6 @@ static void PacketReceived(PacketCommandNG *packet) {
18271827
break;
18281828
}
18291829
case CMD_HF_MIFAREU_READBL: {
1830-
18311830
MifareUReadBlock(packet->oldarg[0], packet->oldarg[1], packet->data.asBytes);
18321831
break;
18331832
}
@@ -2916,20 +2915,22 @@ static void PacketReceived(PacketCommandNG *packet) {
29162915
LED_B_ON();
29172916
uint8_t page = packet->oldarg[0];
29182917
uint8_t initialwipe = packet->oldarg[1];
2918+
29192919
bool isok = false;
29202920
if (initialwipe) {
29212921
isok = Flash_WipeMemory();
2922-
reply_mix(CMD_ACK, isok, 0, 0, 0, 0);
2922+
reply_ng(CMD_FLASHMEM_WIPE, (isok) ? PM3_SUCCESS : PM3_EFAILED, NULL, 0);
29232923
LED_B_OFF();
29242924
break;
29252925
}
2926+
29262927
if (page < spi_flash_pages64k - 1) {
29272928
isok = Flash_WipeMemoryPage(page);
29282929
// let spiffs check and update its info post flash erase
29292930
rdv40_spiffs_check();
29302931
}
29312932

2932-
reply_mix(CMD_ACK, isok, 0, 0, 0, 0);
2933+
reply_ng(CMD_FLASHMEM_WIPE, (isok) ? PM3_SUCCESS : PM3_EFAILED, NULL, 0);
29332934
LED_B_OFF();
29342935
break;
29352936
}
@@ -2950,13 +2951,15 @@ static void PacketReceived(PacketCommandNG *packet) {
29502951
for (size_t i = 0; i < numofbytes; i += PM3_CMD_DATA_SIZE) {
29512952
size_t len = MIN((numofbytes - i), PM3_CMD_DATA_SIZE);
29522953
Flash_CheckBusy(BUSY_TIMEOUT);
2953-
bool isok = Flash_ReadDataCont(startidx + i, mem, len);
2954-
if (isok == false)
2955-
Dbprintf("reading flash memory failed :: | bytes between %d - %d", i, len);
2956-
2954+
uint16_t isok = Flash_ReadDataCont(startidx + i, mem, len);
2955+
if (isok == false) {
2956+
Dbprintf("reading flash memory failed with bytes between %d - %d", i, len);
2957+
}
29572958
isok = reply_old(CMD_FLASHMEM_DOWNLOADED, i, len, 0, mem, len);
2958-
if (isok != 0)
2959-
Dbprintf("transfer to client failed :: | bytes between %d - %d", i, len);
2959+
2960+
if (isok != PM3_SUCCESS) {
2961+
Dbprintf("transfer to client failed with bytes between %d - %d", i, len);
2962+
}
29602963
}
29612964
FlashStop();
29622965

@@ -2968,15 +2971,19 @@ static void PacketReceived(PacketCommandNG *packet) {
29682971
case CMD_FLASHMEM_INFO: {
29692972

29702973
LED_B_ON();
2974+
29712975
rdv40_validation_t *info = (rdv40_validation_t *)BigBuf_calloc(sizeof(rdv40_validation_t));
29722976

2973-
bool isok = Flash_ReadData(FLASH_MEM_SIGNATURE_OFFSET_P(spi_flash_pages64k), info->signature, FLASH_MEM_SIGNATURE_LEN);
2977+
// returns 0 when failing
2978+
uint16_t isok = Flash_ReadData(FLASH_MEM_SIGNATURE_OFFSET_P(spi_flash_pages64k), info->signature, FLASH_MEM_SIGNATURE_LEN);
29742979

2975-
if (FlashInit()) {
2980+
// re-init since command above calls FlashStop()
2981+
if (isok && FlashInit()) {
29762982
Flash_UniqueID(info->flashid);
29772983
FlashStop();
29782984
}
2979-
reply_mix(CMD_ACK, isok, 0, 0, info, sizeof(rdv40_validation_t));
2985+
2986+
reply_ng(CMD_FLASHMEM_INFO, (isok) ? PM3_SUCCESS : PM3_EFLASH, (uint8_t*)info, sizeof(rdv40_validation_t));
29802987
BigBuf_free();
29812988

29822989
LED_B_OFF();
@@ -2986,15 +2993,14 @@ static void PacketReceived(PacketCommandNG *packet) {
29862993

29872994
LED_B_ON();
29882995

2989-
bool isok = false;
2990-
if (FlashInit()) {
2991-
isok = true;
2996+
bool isok = FlashInit();
2997+
if (isok) {
29922998
if (g_dbglevel >= DBG_DEBUG) {
29932999
Dbprintf(" CMD_FLASHMEM_PAGE64K 0x%02x (%d 64k pages)", spi_flash_pages64k, spi_flash_pages64k);
29943000
}
29953001
FlashStop();
29963002
}
2997-
reply_mix(CMD_ACK, isok, 0, 0, &spi_flash_pages64k, sizeof(uint8_t));
3003+
reply_ng(CMD_FLASHMEM_PAGES64K, (isok) ? PM3_SUCCESS : PM3_EFLASH, &spi_flash_pages64k, sizeof(uint8_t));
29983004

29993005
LED_B_OFF();
30003006
break;

armsrc/mifarecmd.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ void MifareValue(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) {
554554

555555
crypto1_deinit(pcs);
556556

557-
if (g_dbglevel >= 2) DbpString("WRITE BLOCK FINISHED");
557+
if (g_dbglevel >= DBG_INFO) DbpString("WRITE BLOCK FINISHED");
558558

559559
reply_mix(CMD_ACK, isOK, 0, 0, 0, 0);
560560

@@ -624,7 +624,7 @@ static void MifareUWriteBlockEx(uint8_t arg0, uint8_t arg1, uint8_t *datain, boo
624624
return;
625625
};
626626

627-
if (g_dbglevel >= 2) DbpString("WRITE BLOCK FINISHED");
627+
if (g_dbglevel >= DBG_INFO) DbpString("WRITE BLOCK FINISHED");
628628

629629
if (reply) {
630630
reply_mix(CMD_ACK, 1, 0, 0, 0, 0);
@@ -699,7 +699,7 @@ void MifareUWriteBlockCompat(uint8_t arg0, uint8_t arg1, uint8_t *datain) {
699699
return;
700700
};
701701

702-
if (g_dbglevel >= 2) DbpString("WRITE BLOCK FINISHED");
702+
if (g_dbglevel >= DBG_INFO) DbpString("WRITE BLOCK FINISHED");
703703

704704
reply_mix(CMD_ACK, 1, 0, 0, 0, 0);
705705
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
@@ -864,7 +864,7 @@ void MifareAcquireNonces(uint32_t arg0, uint32_t flags) {
864864
CHK_TIMEOUT();
865865

866866
if (len != 4) {
867-
if (g_dbglevel >= 2) Dbprintf("AcquireNonces: Auth1 error");
867+
if (g_dbglevel >= DBG_INFO) Dbprintf("AcquireNonces: Auth1 error");
868868
continue;
869869
}
870870

@@ -878,7 +878,7 @@ void MifareAcquireNonces(uint32_t arg0, uint32_t flags) {
878878
reply_old(CMD_ACK, isOK, cuid, num_nonces, buf, sizeof(buf));
879879
LED_B_OFF();
880880

881-
if (g_dbglevel >= 3) DbpString("AcquireNonces finished");
881+
if (g_dbglevel >= DBG_DEBUG) DbpString("AcquireNonces finished");
882882

883883
if (field_off) {
884884
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
@@ -1818,7 +1818,7 @@ static void chkKey_scanA(struct chk_t *c, struct sector_t *k_sector, uint8_t *fo
18181818
found[(s * 2)] = 1;
18191819
++*foundkeys;
18201820

1821-
if (g_dbglevel >= 3) Dbprintf("ChkKeys_fast: Scan A found (%d)", c->block);
1821+
if (g_dbglevel >= DBG_DEBUG) Dbprintf("ChkKeys_fast: Scan A found (%d)", c->block);
18221822
}
18231823
}
18241824
}
@@ -1844,7 +1844,7 @@ static void chkKey_scanB(struct chk_t *c, struct sector_t *k_sector, uint8_t *fo
18441844
found[(s * 2) + 1] = 1;
18451845
++*foundkeys;
18461846

1847-
if (g_dbglevel >= 3) Dbprintf("ChkKeys_fast: Scan B found (%d)", c->block);
1847+
if (g_dbglevel >= DBG_DEBUG) Dbprintf("ChkKeys_fast: Scan B found (%d)", c->block);
18481848
}
18491849
}
18501850
}
@@ -1870,7 +1870,7 @@ static void chkKey_loopBonly(struct chk_t *c, struct sector_t *k_sector, uint8_t
18701870
found[(s * 2) + 1] = 1;
18711871
++*foundkeys;
18721872

1873-
if (g_dbglevel >= 3) Dbprintf("ChkKeys_fast: Reading B found (%d)", c->block);
1873+
if (g_dbglevel >= DBG_DEBUG) Dbprintf("ChkKeys_fast: Reading B found (%d)", c->block);
18741874

18751875
// try quick find all B?
18761876
// assume: keys comes in groups. Find one B, test against all B.

client/src/cmdflashmem.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,17 @@ int rdv4_get_flash_pages64k(uint8_t *pages64k) {
5959
clearCommandBuffer();
6060
SendCommandNG(CMD_FLASHMEM_PAGES64K, NULL, 0);
6161
PacketResponseNG resp;
62-
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
62+
if (WaitForResponseTimeout(CMD_FLASHMEM_PAGES64K, &resp, 2500) == false) {
6363
PrintAndLogEx(WARNING, "rdv4_get_flash_pages64k() timeout while waiting for reply");
6464
return PM3_ETIMEOUT;
6565
}
6666

67-
uint8_t isok = resp.oldarg[0] & 0xFF;
68-
if (isok == false) {
67+
if (resp.status != PM3_SUCCESS) {
6968
PrintAndLogEx(FAILED, "fail reading from flash (pages 64k)");
7069
return PM3_EFLASH;
7170
}
7271

73-
memcpy(pages64k, (uint8_t *)resp.data.asBytes, sizeof(uint8_t));
72+
*pages64k = resp.data.asBytes[0];
7473
return PM3_SUCCESS;
7574
}
7675

@@ -82,18 +81,16 @@ int rdv4_get_signature(rdv40_validation_t *out) {
8281
clearCommandBuffer();
8382
SendCommandNG(CMD_FLASHMEM_INFO, NULL, 0);
8483
PacketResponseNG resp;
85-
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
84+
if (WaitForResponseTimeout(CMD_FLASHMEM_INFO, &resp, 2500) == false) {
8685
PrintAndLogEx(WARNING, "timeout while waiting for reply");
8786
return PM3_ETIMEOUT;
8887
}
8988

90-
uint8_t isok = resp.oldarg[0] & 0xFF;
91-
if (isok == false) {
89+
if (resp.status != PM3_SUCCESS) {
9290
PrintAndLogEx(FAILED, "fail reading from flashmemory");
9391
return PM3_EFLASH;
9492
}
9593

96-
//rdv40_validation_t mem;
9794
memcpy(out, (rdv40_validation_t *)resp.data.asBytes, sizeof(rdv40_validation_t));
9895
return PM3_SUCCESS;
9996
}
@@ -498,7 +495,7 @@ static int CmdFlashMemWipe(const char *Cmd) {
498495

499496
void *argtable[] = {
500497
arg_param_begin,
501-
arg_int0("p", NULL, "<dec>", "0,1,2 page memory"),
498+
arg_int0("p", NULL, "<dec>", "page memory"),
502499
// arg_lit0("i", NULL, "initial total wipe"),
503500
arg_param_end
504501
};
@@ -524,21 +521,19 @@ static int CmdFlashMemWipe(const char *Cmd) {
524521
clearCommandBuffer();
525522
SendCommandMIX(CMD_FLASHMEM_WIPE, page, initialwipe, 0, NULL, 0);
526523
PacketResponseNG resp;
527-
if (!WaitForResponseTimeout(CMD_ACK, &resp, 10000)) {
524+
if (WaitForResponseTimeout(CMD_FLASHMEM_WIPE, &resp, 10000) == false) {
528525
PrintAndLogEx(WARNING, "timeout while waiting for reply");
529526
return PM3_ETIMEOUT;
530527
}
531528

532529
const char *msg = "Flash WIPE ";
533-
uint8_t isok = resp.oldarg[0] & 0xFF;
534-
if (isok)
530+
if (resp.status == PM3_SUCCESS) {
535531
PrintAndLogEx(SUCCESS, "%s ( " _GREEN_("ok")" )", msg);
536-
else {
532+
} else {
537533
PrintAndLogEx(FAILED, "%s ( " _RED_("failed") " )", msg);
538-
return PM3_EFLASH;
539534
}
540535

541-
return PM3_SUCCESS;
536+
return resp.status;
542537
}
543538

544539
static int CmdFlashMemInfo(const char *Cmd) {
@@ -555,7 +550,7 @@ static int CmdFlashMemInfo(const char *Cmd) {
555550
arg_str0("d", NULL, "<hex>", "flash memory id, 8 hex bytes"),
556551
arg_str0("p", "pem", "<fn>", "key in PEM format"),
557552
arg_lit0("v", "verbose", "verbose output"),
558-
// arg_lit0("w", "write", "write signature to flash memory"),
553+
arg_lit0("w", "write", "write signature to flash memory"),
559554
arg_param_end
560555
};
561556
CLIExecWithReturn(ctx, Cmd, argtable, true);
@@ -571,8 +566,7 @@ static int CmdFlashMemInfo(const char *Cmd) {
571566
CLIParamStrToBuf(arg_get_str(ctx, 3), (uint8_t *)pem_fn, FILE_PATH_SIZE, &pemlen);
572567

573568
bool verbose = arg_get_lit(ctx, 4);
574-
bool shall_write = false;
575-
// shall_write = arg_get_lit(ctx, 5);
569+
bool shall_write = arg_get_lit(ctx, 5);
576570
CLIParserFree(ctx);
577571

578572
if (res) {

client/src/cmdhf14a.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ int hf14a_getconfig(hf14a_config_t *config) {
304304

305305
SendCommandNG(CMD_HF_ISO14443A_GET_CONFIG, NULL, 0);
306306
PacketResponseNG resp;
307-
if (!WaitForResponseTimeout(CMD_HF_ISO14443A_GET_CONFIG, &resp, 2000)) {
307+
if (WaitForResponseTimeout(CMD_HF_ISO14443A_GET_CONFIG, &resp, 2000) == false) {
308308
PrintAndLogEx(WARNING, "command execution time out");
309309
return PM3_ETIMEOUT;
310310
}

client/src/cmdhfmfu.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,7 +2905,7 @@ static int CmdHF14AMfURdBl(const char *Cmd) {
29052905
}
29062906

29072907
if (ak_len) {
2908-
PrintAndLogEx(INFO, "Using %s " _GREEN_("%s"), (ak_len == 16) ? "3des" : "pwd", sprint_hex(authenticationkey, ak_len));
2908+
PrintAndLogEx(INFO, "Using %s... " _GREEN_("%s"), (ak_len == 16) ? "3des" : "pwd", sprint_hex_inrow(authenticationkey, ak_len));
29092909
}
29102910

29112911
//Read Block
@@ -2931,7 +2931,7 @@ static int CmdHF14AMfURdBl(const char *Cmd) {
29312931
PrintAndLogEx(INFO, "-----------------------------");
29322932
PrintAndLogEx(INFO, "%02d/0x%02X | %s| %s\n", blockno, blockno, sprint_hex(d, 4), sprint_ascii(d, 4));
29332933
} else {
2934-
PrintAndLogEx(WARNING, "Failed reading block: ( %02x )", isOK);
2934+
PrintAndLogEx(WARNING, "Failed reading block %u ( %02x )", blockno, isOK);
29352935
}
29362936
} else {
29372937
PrintAndLogEx(WARNING, "command execution time out");
@@ -3934,6 +3934,8 @@ static int CmdHF14AMfUCAuth(const char *Cmd) {
39343934

39353935
// If no hex key is specified, try default keys
39363936
if (ak_len == 0) {
3937+
3938+
PrintAndLogEx(INFO, "Called with no key, checking default keys...");
39373939
isok = try_default_3des_keys(false, &authKeyPtr);
39383940
} else {
39393941
// try user-supplied

0 commit comments

Comments
 (0)