From 4761ea13f73e31318b2796fff3ddb8b30c118f56 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 6 Jun 2019 10:05:09 +0200 Subject: [PATCH] MF_DBGLEVEL => DBGLEVEL (pm3 side) --- armsrc/Standalone/hf_bog.c | 16 +-- armsrc/Standalone/hf_colin.c | 14 +-- armsrc/Standalone/hf_mattyrun.c | 2 +- armsrc/appmain.c | 5 +- armsrc/apps.h | 1 - armsrc/felica.c | 6 +- armsrc/flashmem.c | 16 +-- armsrc/fpgaloader.c | 4 +- armsrc/iclass.c | 26 ++--- armsrc/iso14443a.c | 48 ++++---- armsrc/iso14443b.c | 18 +-- armsrc/iso14443b.h | 2 +- armsrc/iso15693.c | 18 +-- armsrc/lfops.c | 4 +- armsrc/mifarecmd.c | 197 +++++++++++++++----------------- armsrc/mifaredesfire.c | 24 ++-- armsrc/mifaresim.c | 168 +++++++++++++-------------- armsrc/mifaresniff.c | 2 +- armsrc/mifareutil.c | 68 +++++------ common/i2c.c | 16 +-- include/common.h | 12 +- 21 files changed, 329 insertions(+), 338 deletions(-) diff --git a/armsrc/Standalone/hf_bog.c b/armsrc/Standalone/hf_bog.c index 151282f3a..0ee0a9066 100644 --- a/armsrc/Standalone/hf_bog.c +++ b/armsrc/Standalone/hf_bog.c @@ -52,7 +52,7 @@ void EraseMemory() { Flash_WriteEnable(); Flash_Erase4k(0, 0); - if (MF_DBGLEVEL > 1) Dbprintf("[!] Erased flash!"); + if (DBGLEVEL > 1) Dbprintf("[!] Erased flash!"); FlashStop(); SpinDelay(100); } @@ -97,7 +97,7 @@ void RAMFUNC SniffAndStore(uint8_t param) { // Setup and start DMA. if (!FpgaSetupSscDma((uint8_t *) dmaBuf, DMA_BUFFER_SIZE)) { - if (MF_DBGLEVEL > 1) Dbprintf("FpgaSetupSscDma failed. Exiting"); + if (DBGLEVEL > 1) Dbprintf("FpgaSetupSscDma failed. Exiting"); return; } @@ -163,7 +163,7 @@ void RAMFUNC SniffAndStore(uint8_t param) { if (triggered) { if ((receivedCmd) && ((receivedCmd[0] == MIFARE_ULEV1_AUTH) || (receivedCmd[0] == MIFARE_ULC_AUTH_1))) { - if (MF_DBGLEVEL > 1) Dbprintf("PWD-AUTH KEY: 0x%02x%02x%02x%02x", receivedCmd[1], receivedCmd[2], receivedCmd[3], receivedCmd[4]); + if (DBGLEVEL > 1) Dbprintf("PWD-AUTH KEY: 0x%02x%02x%02x%02x", receivedCmd[1], receivedCmd[2], receivedCmd[3], receivedCmd[4]); // temporarily save the captured pwd in our array memcpy(&capturedPwds[4 * auth_attempts], receivedCmd + 1, 4); @@ -230,26 +230,26 @@ void RAMFUNC SniffAndStore(uint8_t param) { // Write stuff to flash if (auth_attempts > 0) { - if (MF_DBGLEVEL > 1) Dbprintf("[!] Authentication attempts = %u", auth_attempts); + if (DBGLEVEL > 1) Dbprintf("[!] Authentication attempts = %u", auth_attempts); // Setting the SPI Baudrate to 48MHz to avoid the bit-flip issue (https://github.com/RfidResearchGroup/proxmark3/issues/34) FlashmemSetSpiBaudrate(48000000); // Find the offset in flash mem to continue writing the auth attempts uint8_t memoffset = FindOffsetInFlash(); - if (MF_DBGLEVEL > 1) Dbprintf("[!] Memory offset = %u", memoffset); + if (DBGLEVEL > 1) Dbprintf("[!] Memory offset = %u", memoffset); if ((memoffset + 4 * auth_attempts) > 0xFF) { // We opt to keep the new data only memoffset = 0; - if (MF_DBGLEVEL > 1) Dbprintf("[!] Size of total data > 256 bytes. Discarding the old data."); + if (DBGLEVEL > 1) Dbprintf("[!] Size of total data > 256 bytes. Discarding the old data."); } // Get previous data from flash mem uint8_t *previousdata = BigBuf_malloc(memoffset); if (memoffset > 0) { uint16_t readlen = Flash_ReadData(0, previousdata, memoffset); - if (MF_DBGLEVEL > 1) Dbprintf("[!] Read %u bytes from flash mem", readlen); + if (DBGLEVEL > 1) Dbprintf("[!] Read %u bytes from flash mem", readlen); } // create new bigbuf to hold all data @@ -267,7 +267,7 @@ void RAMFUNC SniffAndStore(uint8_t param) { // Write total data to flash mem uint16_t writelen = Flash_WriteData(0, total_data, memoffset + 4 * auth_attempts); - if (MF_DBGLEVEL > 1) Dbprintf("[!] Wrote %u bytes into flash mem", writelen); + if (DBGLEVEL > 1) Dbprintf("[!] Wrote %u bytes into flash mem", writelen); // If pwd saved successfully, blink led A three times if (writelen > 0) { diff --git a/armsrc/Standalone/hf_colin.c b/armsrc/Standalone/hf_colin.c index 22467f2d3..b16f1c610 100644 --- a/armsrc/Standalone/hf_colin.c +++ b/armsrc/Standalone/hf_colin.c @@ -827,7 +827,7 @@ readysim: * - tracing is falsed */ int e_MifareECardLoad(uint32_t numofsectors, uint8_t keytype) { - MF_DBGLEVEL = MF_DBG_NONE; + DBGLEVEL = DBG_NONE; uint8_t numSectors = numofsectors; uint8_t keyType = keytype; @@ -848,7 +848,7 @@ int e_MifareECardLoad(uint32_t numofsectors, uint8_t keytype) { if (!iso14443a_select_card(cjuid, &p_card, &cjcuid, true, 0, true)) { isOK = false; - if (MF_DBGLEVEL >= 1) + if (DBGLEVEL >= 1) DbprintfEx(FLAG_RAWPRINT, "Can't select card"); } @@ -857,14 +857,14 @@ int e_MifareECardLoad(uint32_t numofsectors, uint8_t keytype) { if (s == 0) { if (isOK && mifare_classic_auth(pcs, cjcuid, FirstBlockOfSector(s), keyType, ui64Key, AUTH_FIRST)) { - if (MF_DBGLEVEL >= 1) + if (DBGLEVEL >= 1) DbprintfEx(FLAG_NEWLINE, "Sector[%2d]. Auth error", s); break; } } else { if (isOK && mifare_classic_auth(pcs, cjcuid, FirstBlockOfSector(s), keyType, ui64Key, AUTH_NESTED)) { isOK = false; - if (MF_DBGLEVEL >= 1) + if (DBGLEVEL >= 1) DbprintfEx(FLAG_NEWLINE, "Sector[%2d]. Auth nested error", s); break; } @@ -873,7 +873,7 @@ int e_MifareECardLoad(uint32_t numofsectors, uint8_t keytype) { for (uint8_t blockNo = 0; isOK && blockNo < NumBlocksPerSector(s); blockNo++) { if (isOK && mifare_classic_readblock(pcs, cjcuid, FirstBlockOfSector(s) + blockNo, dataoutbuf)) { isOK = false; - if (MF_DBGLEVEL >= 1) + if (DBGLEVEL >= 1) DbprintfEx(FLAG_NEWLINE, "Error reading sector %2d block %2d", s, blockNo); break; }; @@ -891,7 +891,7 @@ int e_MifareECardLoad(uint32_t numofsectors, uint8_t keytype) { } if (mifare_classic_halt(pcs, cjcuid)) { - if (MF_DBGLEVEL >= 1) + if (DBGLEVEL >= 1) DbprintfEx(FLAG_NEWLINE, "Halt error"); }; @@ -905,7 +905,7 @@ int e_MifareECardLoad(uint32_t numofsectors, uint8_t keytype) { /* the chk function is a piwi’ed(tm) check that will try all keys for a particular sector. also no tracing no dbg */ int cjat91_saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, uint8_t keyCount, uint8_t *datain, uint64_t *key) { - MF_DBGLEVEL = MF_DBG_NONE; + DBGLEVEL = DBG_NONE; iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); set_tracing(false); diff --git a/armsrc/Standalone/hf_mattyrun.c b/armsrc/Standalone/hf_mattyrun.c index b34af0571..e7be77bd7 100644 --- a/armsrc/Standalone/hf_mattyrun.c +++ b/armsrc/Standalone/hf_mattyrun.c @@ -156,7 +156,7 @@ static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_ /* the chk function is a piwi’ed(tm) check that will try all keys for a particular sector. also no tracing no dbg */ static int saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, uint8_t keyCount, uint8_t *datain, uint64_t *key) { - MF_DBGLEVEL = MF_DBG_NONE; + DBGLEVEL = DBG_NONE; iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); set_tracing(false); diff --git a/armsrc/appmain.c b/armsrc/appmain.c index c54fb6626..916801954 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -418,7 +418,7 @@ void SendStatus(void) { #endif printConnSpeed(); DbpString(_BLUE_("Various")); - Dbprintf(" MF_DBGLEVEL.............%d", MF_DBGLEVEL); + Dbprintf(" DBGLEVEL................%d", DBGLEVEL); Dbprintf(" ToSendMax...............%d", ToSendMax); Dbprintf(" ToSendBit...............%d", ToSendBit); Dbprintf(" ToSend BUFFERSIZE.......%d", TOSEND_BUFFER_SIZE); @@ -1116,7 +1116,8 @@ static void PacketReceived(PacketCommandNG *packet) { } // emulator case CMD_MIFARE_SET_DBGMODE: - MifareSetDbgLvl(packet->data.asBytes[0]); + DBGLEVEL = packet->data.asBytes[0]; + Dbprintf("Debug level: %d", DBGLEVEL); reply_ng(CMD_MIFARE_SET_DBGMODE, PM3_SUCCESS, NULL, 0); break; case CMD_MIFARE_EML_MEMCLR: diff --git a/armsrc/apps.h b/armsrc/apps.h index 561a08b0d..59832d6b4 100644 --- a/armsrc/apps.h +++ b/armsrc/apps.h @@ -160,7 +160,6 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, void MifareAcquireNonces(uint32_t arg0, uint32_t flags); void MifareChkKeys(uint8_t *datain); void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain); -void MifareSetDbgLvl(uint16_t arg0); void MifareEMemClr(void); void MifareEMemSet(uint8_t blockno, uint8_t blockcnt, uint8_t blockwidth, uint8_t *datain); diff --git a/armsrc/felica.c b/armsrc/felica.c index 58d976774..48b6f4464 100644 --- a/armsrc/felica.c +++ b/armsrc/felica.c @@ -176,7 +176,7 @@ static void Process18092Byte(uint8_t bt) { FelicaFrame.crc_ok = check_crc(CRC_FELICA, FelicaFrame.framebytes + 2, FelicaFrame.len - 2); FelicaFrame.state = STATE_FULL; FelicaFrame.rem_len = 0; - if (MF_DBGLEVEL > 3) Dbprintf("[+] got 2 crc bytes [%s]", (FelicaFrame.crc_ok) ? "OK" : "No"); + if (DBGLEVEL > 3) Dbprintf("[+] got 2 crc bytes [%s]", (FelicaFrame.crc_ok) ? "OK" : "No"); } break; } @@ -477,7 +477,7 @@ static void iso18092_setup(uint8_t fpga_minor_mode) { // d.asBytes command bytes to send void felica_sendraw(PacketCommandNG *c) { - if (MF_DBGLEVEL > 3) Dbprintf("FeliCa_sendraw Enter"); + if (DBGLEVEL > 3) Dbprintf("FeliCa_sendraw Enter"); felica_command_t param = c->oldarg[0]; size_t len = c->oldarg[1] & 0xffff; @@ -537,7 +537,7 @@ OUT: //Resetting Frame mode (First set in fpgaloader.c) AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0); - if (MF_DBGLEVEL > 3) Dbprintf("FeliCa_sendraw Exit"); + if (DBGLEVEL > 3) Dbprintf("FeliCa_sendraw Exit"); } void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) { diff --git a/armsrc/flashmem.c b/armsrc/flashmem.c index 5bdbfff90..4584d41b2 100644 --- a/armsrc/flashmem.c +++ b/armsrc/flashmem.c @@ -149,7 +149,7 @@ void FlashStop(void) { // SPI disable AT91C_BASE_SPI->SPI_CR = AT91C_SPI_SPIDIS; - if (MF_DBGLEVEL > 3) Dbprintf("FlashStop"); + if (DBGLEVEL > 3) Dbprintf("FlashStop"); StopTicks(); } @@ -189,7 +189,7 @@ bool Flash_CheckBusy(uint32_t timeout) { StartCountUS(); uint32_t _time = GetCountUS(); - if (MF_DBGLEVEL > 3) Dbprintf("Checkbusy in..."); + if (DBGLEVEL > 3) Dbprintf("Checkbusy in..."); do { if (!(Flash_ReadStat1() & BUSY)) { @@ -218,7 +218,7 @@ uint8_t Flash_ReadID(void) { uint8_t man_id = FlashSendByte(0xFF); uint8_t dev_id = FlashSendLastByte(0xFF); - if (MF_DBGLEVEL > 3) Dbprintf("Flash ReadID | Man ID %02x | Device ID %02x", man_id, dev_id); + if (DBGLEVEL > 3) Dbprintf("Flash ReadID | Man ID %02x | Device ID %02x", man_id, dev_id); if ((man_id == WINBOND_MANID) && (dev_id == WINBOND_DEVID)) return dev_id; @@ -325,7 +325,7 @@ uint16_t Flash_WriteData(uint32_t address, uint8_t *in, uint16_t len) { } if (!FlashInit()) { - if (MF_DBGLEVEL > 3) Dbprintf("Flash_WriteData init fail"); + if (DBGLEVEL > 3) Dbprintf("Flash_WriteData init fail"); return 0; } @@ -415,7 +415,7 @@ out: bool Flash_WipeMemoryPage(uint8_t page) { if (!FlashInit()) { - if (MF_DBGLEVEL > 3) Dbprintf("Flash_WriteData init fail"); + if (DBGLEVEL > 3) Dbprintf("Flash_WriteData init fail"); return false; } Flash_ReadStat1(); @@ -431,7 +431,7 @@ bool Flash_WipeMemoryPage(uint8_t page) { // Wipes flash memory completely, fills with 0xFF bool Flash_WipeMemory() { if (!FlashInit()) { - if (MF_DBGLEVEL > 3) Dbprintf("Flash_WriteData init fail"); + if (DBGLEVEL > 3) Dbprintf("Flash_WriteData init fail"); return false; } Flash_ReadStat1(); @@ -458,7 +458,7 @@ bool Flash_WipeMemory() { // enable the flash write void Flash_WriteEnable() { FlashSendLastByte(WRITEENABLE); - if (MF_DBGLEVEL > 3) Dbprintf("Flash Write enabled"); + if (DBGLEVEL > 3) Dbprintf("Flash Write enabled"); } // erase 4K at one time @@ -479,7 +479,7 @@ bool Flash_Erase4k(uint8_t block, uint8_t sector) { // execution time: 0,3s / 300ms bool Flash_Erase32k(uint32_t address) { if (address & (32*1024 - 1)) { - if ( MF_DBGLEVEL > 1 ) Dbprintf("Flash_Erase32k : Address is not align at 4096"); + if ( DBGLEVEL > 1 ) Dbprintf("Flash_Erase32k : Address is not align at 4096"); return false; } FlashSendByte(BLOCK32ERASE); diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c index dcaaa238a..7e920a360 100644 --- a/armsrc/fpgaloader.c +++ b/armsrc/fpgaloader.c @@ -398,7 +398,7 @@ void FpgaDownloadAndGo(int bitstream_version) { z_stream compressed_fpga_stream; uint8_t output_buffer[OUTPUT_BUFFER_LEN] = {0x00}; - bool verbose = (MF_DBGLEVEL > 3); + bool verbose = (DBGLEVEL > 3); // make sure that we have enough memory to decompress BigBuf_free(); @@ -496,7 +496,7 @@ int FpgaGetCurrent(void) { // if HF, Disable SSC DMA // turn off trace and leds off. void switch_off(void) { - if (MF_DBGLEVEL > 3) Dbprintf("switch_off"); + if (DBGLEVEL > 3) Dbprintf("switch_off"); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); if (downloaded_bitstream == FPGA_BITSTREAM_HF) FpgaDisableSscDma(); diff --git a/armsrc/iclass.c b/armsrc/iclass.c index c12c9dc1f..25d224184 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -798,7 +798,7 @@ static RAMFUNC int ManchesterDecoding_iclass(uint32_t v) { // Both sides of communication! //============================================================================= static void iclass_setup_sniff(void) { - if (MF_DBGLEVEL > 3) Dbprintf("iclass_setup_sniff Enter"); + if (DBGLEVEL > 3) Dbprintf("iclass_setup_sniff Enter"); LEDsoff(); @@ -823,7 +823,7 @@ static void iclass_setup_sniff(void) { uart_init(BigBuf_malloc(ICLASS_BUFFER_SIZE)); //UartInit(BigBuf_malloc(ICLASS_BUFFER_SIZE)); - if (MF_DBGLEVEL > 1) { + if (DBGLEVEL > 1) { // Print debug information about the buffer sizes Dbprintf("[+] Sniffing buffers initialized:"); Dbprintf(" Trace: %i bytes", BigBuf_max_traceLen()); @@ -841,7 +841,7 @@ static void iclass_setup_sniff(void) { StartCountSspClk(); LED_A_ON(); - if (MF_DBGLEVEL > 3) Dbprintf("[+] iclass_setup_sniff Exit"); + if (DBGLEVEL > 3) Dbprintf("[+] iclass_setup_sniff Exit"); } //----------------------------------------------------------------------------- @@ -869,7 +869,7 @@ void RAMFUNC SniffIClass(void) { // Setup and start DMA. if (!FpgaSetupSscDma(dmaBuf, ICLASS_DMA_BUFFER_SIZE)) { - if (MF_DBGLEVEL > 1) DbpString("[-] FpgaSetupSscDma failed. Exiting"); + if (DBGLEVEL > 1) DbpString("[-] FpgaSetupSscDma failed. Exiting"); return; } @@ -964,7 +964,7 @@ void RAMFUNC SniffIClass(void) { } } // end main loop - if (MF_DBGLEVEL >= 1) { + if (DBGLEVEL >= 1) { DbpString("[+] Sniff statistics:"); Dbhexdump(ICLASS_DMA_BUFFER_SIZE, data, false); } @@ -1149,7 +1149,7 @@ static void CodeIClassTagSOF() { // turn off afterwards void SimulateIClass(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) { - if (MF_DBGLEVEL > 3) Dbprintf("[+] iClass_simulate Enter"); + if (DBGLEVEL > 3) Dbprintf("[+] iClass_simulate Enter"); LEDsoff(); @@ -1519,7 +1519,7 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) { if (simulationMode == MODE_EXIT_AFTER_MAC) { - if (MF_DBGLEVEL == MF_DBG_EXTENDED) { + if (DBGLEVEL == DBG_EXTENDED) { Dbprintf("[+] CSN: %02x %02x %02x %02x %02x %02x %02x %02x", csn[0], csn[1], csn[2], csn[3], csn[4], csn[5], csn[6], csn[7]); Dbprintf("[+] RDR: (len=%02d): %02x %02x %02x %02x %02x %02x %02x %02x %02x", len, receivedCmd[0], receivedCmd[1], receivedCmd[2], @@ -1584,7 +1584,7 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) { } else { //#db# Unknown command received from reader (len=5): 26 1 0 f6 a 44 44 44 44 // Never seen this command before - if (MF_DBGLEVEL == MF_DBG_EXTENDED) + if (DBGLEVEL == DBG_EXTENDED) print_result("[-] Unhandled command received ", receivedCmd, len); // Do not respond @@ -2000,7 +2000,7 @@ void ReaderIClass(uint8_t arg0) { // if only looking for one card try 2 times if we missed it the first time if (try_once && tryCnt > 2) { - if (MF_DBGLEVEL > 1) DbpString("Failed to find a tag"); + if (DBGLEVEL > 1) DbpString("Failed to find a tag"); break; } @@ -2024,7 +2024,7 @@ void ReaderIClass(uint8_t arg0) { result_status |= FLAG_ICLASS_READER_CONF; memcpy(card_data + 8, resp, 8); } else { - if (MF_DBGLEVEL > 1) DbpString("Failed to dump config block"); + if (DBGLEVEL > 1) DbpString("Failed to dump config block"); } } @@ -2034,7 +2034,7 @@ void ReaderIClass(uint8_t arg0) { result_status |= FLAG_ICLASS_READER_AIA; memcpy(card_data + (8 * 5), resp, 8); } else { - if (MF_DBGLEVEL > 1) DbpString("Failed to dump AA block"); + if (DBGLEVEL > 1) DbpString("Failed to dump AA block"); } } @@ -2053,7 +2053,7 @@ void ReaderIClass(uint8_t arg0) { // only useful if looping in arm (not try_once && not abort_after_read) if (memcmp(last_csn, card_data, 8) != 0) { // If caller requires that we get Conf, CC, AA, continue until we got it - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { Dbprintf("STATUS %02X | CSN %c | CONF %c | CC %c | AIA %c | ONCE %c | 1TRY %c", result_status, (result_status & FLAG_ICLASS_READER_CSN) ? 'Y' : 'N', @@ -2079,7 +2079,7 @@ void ReaderIClass(uint8_t arg0) { if (flagReadConfig) send |= (result_status & FLAG_ICLASS_READER_CONF); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("SEND %c", send ? 'y' : 'n'); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("SEND %c", send ? 'y' : 'n'); if (send) { reply_old(CMD_ACK, result_status, 0, 0, card_data, sizeof(card_data)); diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index 8d5bceccc..330dc357e 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -513,7 +513,7 @@ void RAMFUNC SniffIso14443a(uint8_t param) { // Setup and start DMA. if (!FpgaSetupSscDma((uint8_t *) dmaBuf, DMA_BUFFER_SIZE)) { - if (MF_DBGLEVEL > 1) Dbprintf("FpgaSetupSscDma failed. Exiting"); + if (DBGLEVEL > 1) Dbprintf("FpgaSetupSscDma failed. Exiting"); return; } @@ -624,7 +624,7 @@ void RAMFUNC SniffIso14443a(uint8_t param) { } } // end main loop - if (MF_DBGLEVEL >= MF_DBG_ERROR) { + if (DBGLEVEL >= DBG_ERROR) { Dbprintf("maxDataLen=%d, Uart.state=%x, Uart.len=%d", maxDataLen, Uart.state, Uart.len); Dbprintf("traceLen=" _YELLOW_("%d")", Uart.output[0]="_YELLOW_("%08x"), BigBuf_get_traceLen(), (uint32_t)Uart.output[0]); } @@ -912,7 +912,7 @@ static bool SimulateIso14443aInit(int tagType, int flags, uint8_t *data, tag_res } break; default: { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Error: unkown tagtype (%d)", tagType); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Error: unkown tagtype (%d)", tagType); return false; } break; @@ -957,7 +957,7 @@ static bool SimulateIso14443aInit(int tagType, int flags, uint8_t *data, tag_res sak &= 0xFB; *cuid = bytes_to_num(data, 4); } else { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("[-] ERROR: UID size not defined"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("[-] ERROR: UID size not defined"); return false; } @@ -1003,7 +1003,7 @@ static bool SimulateIso14443aInit(int tagType, int flags, uint8_t *data, tag_res for (size_t i = 0; i < TAG_RESPONSE_COUNT; i++) { if (prepare_allocated_tag_modulation(&responses_init[i], &free_buffer_pointer, &free_buffer_size) == false) { BigBuf_free_keep_EM(); - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Not enough modulation buffer size, exit after %d elements", i); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Not enough modulation buffer size, exit after %d elements", i); return false; } } @@ -1403,7 +1403,7 @@ void SimulateIso14443aTag(uint8_t tagType, uint8_t flags, uint8_t *data) { } else { EmSend4bit(CARD_NACK_NA); uint32_t pwd = bytes_to_num(receivedCmd + 1, 4); - if (MF_DBGLEVEL >= MF_DBG_DEBUG) Dbprintf("Auth attempt: %08x", pwd); + if (DBGLEVEL >= DBG_DEBUG) Dbprintf("Auth attempt: %08x", pwd); } p_response = NULL; } else if (receivedCmd[0] == MIFARE_ULEV1_VCSL && len == 23 && tagType == 7) { @@ -1465,7 +1465,7 @@ void SimulateIso14443aTag(uint8_t tagType, uint8_t flags, uint8_t *data) { default: { // Never seen this command before LogTrace(receivedCmd, Uart.len, Uart.startTime * 16 - DELAY_AIR2ARM_AS_TAG, Uart.endTime * 16 - DELAY_AIR2ARM_AS_TAG, Uart.parity, true); - if (MF_DBGLEVEL >= MF_DBG_DEBUG) { + if (DBGLEVEL >= DBG_DEBUG) { Dbprintf("Received unknown command (len=%d):", len); Dbhexdump(len, receivedCmd, false); } @@ -1485,7 +1485,7 @@ void SimulateIso14443aTag(uint8_t tagType, uint8_t flags, uint8_t *data) { dynamic_response_info.response_n += 2; if (prepare_tag_modulation(&dynamic_response_info, DYNAMIC_MODULATION_BUFFER_SIZE) == false) { - if (MF_DBGLEVEL >= MF_DBG_DEBUG) DbpString("Error preparing tag response"); + if (DBGLEVEL >= DBG_DEBUG) DbpString("Error preparing tag response"); LogTrace(receivedCmd, Uart.len, Uart.startTime * 16 - DELAY_AIR2ARM_AS_TAG, Uart.endTime * 16 - DELAY_AIR2ARM_AS_TAG, Uart.parity, true); break; } @@ -1511,7 +1511,7 @@ void SimulateIso14443aTag(uint8_t tagType, uint8_t flags, uint8_t *data) { set_tracing(false); BigBuf_free_keep_EM(); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { Dbprintf("-[ Wake ups after halt [%d]", happened); Dbprintf("-[ Messages after halt [%d]", happened2); Dbprintf("-[ Num of received cmd [%d]", cmdsRecvd); @@ -1563,7 +1563,7 @@ static void TransmitFor14443a(const uint8_t *cmd, uint16_t len, uint32_t *timing else PrepareDelayedTransfer(*timing & 0x00000007); // Delay transfer (fine tuning - up to 7 MF clock ticks) - if (MF_DBGLEVEL >= MF_DBG_EXTENDED && GetCountSspClk() >= (*timing & 0xfffffff8)) + if (DBGLEVEL >= DBG_EXTENDED && GetCountSspClk() >= (*timing & 0xfffffff8)) Dbprintf("TransmitFor14443a: Missed timing"); while (GetCountSspClk() < (*timing & 0xfffffff8)) {}; // Delay transfer (multiple of 8 MF clock ticks) LastTimeProxToAirStart = *timing; @@ -1891,7 +1891,7 @@ int EmSendPrecompiledCmd(tag_response_info_t *p_response) { (LastTimeProxToAirStart + p_response->ProxToAirDuration) * 16 + DELAY_ARM2AIR_AS_TAG, par); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { Dbprintf("response_info->response %02X", p_response->response); Dbprintf("response_info->response_n %02X", p_response->response_n); Dbprintf("response_info->par %02X", &(p_response->par)); @@ -2058,12 +2058,12 @@ void iso14443a_antifuzz(uint32_t flags) { } EmSendCmdEx(resp, 5, true); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("ANTICOLL or SELECT %x", received[1]); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("ANTICOLL or SELECT %x", received[1]); LED_D_INV(); continue; } else if (received[1] == 0x20 && received[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_2) { // Received request for UID (cascade 2) - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("ANTICOLL or SELECT_2"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("ANTICOLL or SELECT_2"); } else if (received[1] == 0x70 && received[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT) { // Received a SELECT (cascade 1) } else if (received[1] == 0x70 && received[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_2) { // Received a SELECT (cascade 2) } else { @@ -2681,7 +2681,7 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) { if (!have_uid) { // need a full select cycle to get the uid first iso14a_card_select_t card_info; if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Mifare: Can't select card (ALL)"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Mifare: Can't select card (ALL)"); continue; } switch (card_info.uidlen) { @@ -2700,7 +2700,7 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) { have_uid = true; } else { // no need for anticollision. We can directly select the card if (!iso14443a_fast_select_card(uid, cascade_levels)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Mifare: Can't select card (UID)"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Mifare: Can't select card (UID)"); continue; } } @@ -2772,7 +2772,7 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) { sync_time = GetCountSspClk() & 0xfffffff8; } - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("calibrating in cycle %d. nt_distance=%d, elapsed_prng_sequences=%d, new sync_cycles: %d\n", i, nt_distance, elapsed_prng_sequences, sync_cycles); LED_B_OFF(); @@ -2799,13 +2799,13 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) { } if (consecutive_resyncs < 3) { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { Dbprintf("Lost sync in cycle %d. nt_distance=%d. Consecutive Resyncs = %d. Trying one time catch up...\n", i, catch_up_cycles, consecutive_resyncs); } } else { sync_cycles += catch_up_cycles; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Lost sync in cycle %d for the fourth time consecutively (nt_distance = %d). Adjusting sync_cycles to %d.\n", i, catch_up_cycles, sync_cycles); last_catch_up = 0; @@ -2855,7 +2855,7 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) { mf_nr_ar[3] &= 0x1F; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Number of sent auth requestes: %u", i); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Number of sent auth requestes: %u", i); uint8_t buf[32] = {0x00}; memset(buf, 0x00, sizeof(buf)); @@ -2932,7 +2932,7 @@ void DetectNACKbug() { if (!have_uid) { // need a full select cycle to get the uid first iso14a_card_select_t card_info; if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Mifare: Can't select card (ALL)"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Mifare: Can't select card (ALL)"); i = 0; continue; } @@ -2954,7 +2954,7 @@ void DetectNACKbug() { have_uid = true; } else { // no need for anticollision. We can directly select the card if (!iso14443a_fast_select_card(uid, cascade_levels)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Mifare: Can't select card (UID)"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Mifare: Can't select card (UID)"); i = 0; have_uid = false; continue; @@ -3034,7 +3034,7 @@ void DetectNACKbug() { break; } - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("calibrating in cycle %d. nt_distance=%d, elapsed_prng_sequences=%d, new sync_cycles: %d\n", i, nt_distance, elapsed_prng_sequences, sync_cycles); continue; @@ -3061,13 +3061,13 @@ void DetectNACKbug() { } if (consecutive_resyncs < 3) { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { Dbprintf("Lost sync in cycle %d. nt_distance=%d. Consecutive Resyncs = %d. Trying one time catch up...\n", i, catch_up_cycles, consecutive_resyncs); } } else { sync_cycles += catch_up_cycles; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { Dbprintf("Lost sync in cycle %d for the fourth time consecutively (nt_distance = %d). Adjusting sync_cycles to %d.\n", i, catch_up_cycles, sync_cycles); Dbprintf("nt [%08x] attacted [%08x]", nt, nt_attacked); } diff --git a/armsrc/iso14443b.c b/armsrc/iso14443b.c index ffdfc41dd..24c993f0b 100644 --- a/armsrc/iso14443b.c +++ b/armsrc/iso14443b.c @@ -159,14 +159,14 @@ static void iso14b_set_timeout(uint32_t timeout) { timeout = MAX_TIMEOUT; iso14b_timeout = timeout; - if (MF_DBGLEVEL >= 3) Dbprintf("ISO14443B Timeout set to %ld fwt", iso14b_timeout); + if (DBGLEVEL >= 3) Dbprintf("ISO14443B Timeout set to %ld fwt", iso14b_timeout); } static void iso14b_set_maxframesize(uint16_t size) { if (size > 256) size = MAX_FRAME_SIZE; Uart.byteCntMax = size; - if (MF_DBGLEVEL >= 3) Dbprintf("ISO14443B Max frame size set to %d bytes", Uart.byteCntMax); + if (DBGLEVEL >= 3) Dbprintf("ISO14443B Max frame size set to %d bytes", Uart.byteCntMax); } //----------------------------------------------------------------------------- @@ -714,7 +714,7 @@ void SimulateIso14443bTag(uint32_t pupi) { ++cmdsReceived; } - if (MF_DBGLEVEL >= 2) + if (DBGLEVEL >= 2) Dbprintf("Emulator stopped. Trace length: %d ", BigBuf_get_traceLen()); switch_off(); //simulate } @@ -960,7 +960,7 @@ static void GetTagSamplesFor14443bDemod() { // Setup and start DMA. if (!FpgaSetupSscDma((uint8_t *) dmaBuf, ISO14443B_DMA_BUFFER_SIZE)) { - if (MF_DBGLEVEL > 1) Dbprintf("FpgaSetupSscDma failed. Exiting"); + if (DBGLEVEL > 1) Dbprintf("FpgaSetupSscDma failed. Exiting"); return; } @@ -1161,7 +1161,7 @@ uint8_t iso14443b_apdu(uint8_t const *message, size_t message_length, uint8_t *r // VALIDATE CRC if (!check_crc(CRC_14443_B, Demod.output, Demod.len)) { - if (MF_DBGLEVEL > 3) Dbprintf("crc fail ICE"); + if (DBGLEVEL > 3) Dbprintf("crc fail ICE"); return 0; } // copy response contents @@ -1419,7 +1419,7 @@ static void iso1444b_setup_sniff(void) { DemodInit(BigBuf_malloc(MAX_FRAME_SIZE)); UartInit(BigBuf_malloc(MAX_FRAME_SIZE)); - if (MF_DBGLEVEL > 1) { + if (DBGLEVEL > 1) { // Print debug information about the buffer sizes Dbprintf("[+] Sniff buffers initialized:"); Dbprintf("[+] trace: %i bytes", BigBuf_max_traceLen()); @@ -1478,7 +1478,7 @@ void RAMFUNC SniffIso14443b(void) { // Setup and start DMA. if (!FpgaSetupSscDma((uint8_t *) dmaBuf, ISO14443B_DMA_BUFFER_SIZE)) { - if (MF_DBGLEVEL > 1) Dbprintf("[!] FpgaSetupSscDma failed. Exiting"); + if (DBGLEVEL > 1) Dbprintf("[!] FpgaSetupSscDma failed. Exiting"); BigBuf_free(); return; } @@ -1542,7 +1542,7 @@ void RAMFUNC SniffIso14443b(void) { } } - if (MF_DBGLEVEL >= 2) { + if (DBGLEVEL >= 2) { DbpString("[+] Sniff statistics:"); Dbprintf("[+] uart State: %x ByteCount: %i ByteCountMax: %i", Uart.state, Uart.byteCnt, Uart.byteCntMax); Dbprintf("[+] trace length: %i", BigBuf_get_traceLen()); @@ -1575,7 +1575,7 @@ void SendRawCommand14443B_Ex(PacketCommandNG *c) { uint32_t sendlen = sizeof(iso14b_card_select_t); uint8_t buf[PM3_CMD_DATA_SIZE] = {0x00}; - if (MF_DBGLEVEL > 3) Dbprintf("14b raw: param, %04x", param); + if (DBGLEVEL > 3) Dbprintf("14b raw: param, %04x", param); // turn on trigger (LED_A) if ((param & ISO14B_REQUEST_TRIGGER) == ISO14B_REQUEST_TRIGGER) diff --git a/armsrc/iso14443b.h b/armsrc/iso14443b.h index 2618b0770..5ea3d530b 100644 --- a/armsrc/iso14443b.h +++ b/armsrc/iso14443b.h @@ -18,7 +18,7 @@ extern "C" { #endif #include "proxmark3.h" -#include "common.h" // access to global variable: MF_DBGLEVEL +#include "common.h" // access to global variable: DBGLEVEL #include "apps.h" #include "util.h" #include "string.h" diff --git a/armsrc/iso15693.c b/armsrc/iso15693.c index c7d15a824..e42a35499 100644 --- a/armsrc/iso15693.c +++ b/armsrc/iso15693.c @@ -330,7 +330,7 @@ static int DemodAnswer(uint8_t *received, uint8_t *dest, uint16_t samplecount) { // Even things out by the length of the target waveform. corr0 *= 4; corr1 *= 4; - // if (MF_DBGLEVEL >= MF_DBG_EXTENDED) + // if (DBGLEVEL >= DBG_EXTENDED) // Dbprintf("Corr1 %d, Corr0 %d, CorrEOF %d", corr1, corr0, corrEOF); if (corrEOF > corr1 && corrEOF > corr0) @@ -356,12 +356,12 @@ static int DemodAnswer(uint8_t *received, uint8_t *dest, uint16_t samplecount) { } } - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("ice: demod bytes %u", k); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("ice: demod bytes %u", k); if (mask != 0x01) { // this happens, when we miss the EOF // TODO: for some reason this happens quite often - if (MF_DBGLEVEL >= MF_DBG_ERROR && k != 0) Dbprintf("[!] error, uneven octet! (extra bits!) mask %02x", mask); + if (DBGLEVEL >= DBG_ERROR && k != 0) Dbprintf("[!] error, uneven octet! (extra bits!) mask %02x", mask); //if (mask < 0x08) k--; // discard the last uneven octet; // 0x08 is an assumption - but works quite often } @@ -785,7 +785,7 @@ void DbdecodeIso15693Answer(int len, uint8_t *d) { else strncat(status, "[!] crc fail", DBD15STATLEN - strlen(status)); - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("%s", status); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("%s", status); } } @@ -838,7 +838,7 @@ void ReaderIso15693(uint32_t parameter) { uid[6] = answer1[3]; uid[7] = answer1[2]; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { Dbprintf("[+] UID = %02X%02X%02X%02X%02X%02X%02X%02X", uid[0], uid[1], uid[2], uid[3], uid[4], uid[5], uid[5], uid[6] @@ -852,7 +852,7 @@ void ReaderIso15693(uint32_t parameter) { reply_old(CMD_ACK, 1, sizeof(uid), 0, uid, sizeof(uid)); } - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { Dbprintf("[+] %d octets read from IDENTIFY request:", answerLen1); DbdecodeIso15693Answer(answerLen1, answer1); Dbhexdump(answerLen1, answer1, true); @@ -904,7 +904,7 @@ void SimTagIso15693(uint32_t parameter, uint8_t *uid) { TransmitTo15693Reader(ToSend, ToSendMax, &tsamples, &wait); LogTrace(cmd, CMD_INV_RESP, time_start << 4, (GetCountSspClk() - time_start) << 4, NULL, true); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { Dbprintf("[+] %d octets read from reader command: %x %x %x %x %x %x %x %x", ans, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7] @@ -978,7 +978,7 @@ void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint uint8_t buf[ISO15_MAX_FRAME]; memset(buf, 0x00, sizeof(buf)); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { DbpString("[+] SEND"); Dbhexdump(datalen, data, true); } @@ -992,7 +992,7 @@ void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint reply_old(CMD_ACK, buflen, 0, 0, buf, buflen); LED_B_OFF(); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { DbpString("[+] RECV"); DbdecodeIso15693Answer(buflen, buf); Dbhexdump(buflen, buf, true); diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 870b56303..de4c412ca 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -99,7 +99,7 @@ void setT55xxConfig(uint8_t arg0, t55xx_config *c) { Flash_Erase4k(3, 0xD); res = Flash_Write(T55XX_CONFIG_OFFSET, buf, T55XX_CONFIG_LEN); - if (res == T55XX_CONFIG_LEN && MF_DBGLEVEL > 1) { + if (res == T55XX_CONFIG_LEN && DBGLEVEL > 1) { DbpString("T55XX Config save success"); } @@ -137,7 +137,7 @@ void loadT55xxConfig(void) { memcpy((uint8_t *)&t_config, buf, T55XX_CONFIG_LEN); if (isok == T55XX_CONFIG_LEN) { - if (MF_DBGLEVEL > 1) DbpString("T55XX Config load success"); + if (DBGLEVEL > 1) DbpString("T55XX Config load success"); } #endif } diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index f64723355..f7a710c0e 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -63,22 +63,22 @@ void MifareReadBlock(uint8_t blockNo, uint8_t keyType, uint8_t *datain) { while (true) { if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card"); + if (DBGLEVEL >= 1) Dbprintf("Can't select card"); break; }; if (mifare_classic_auth(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Auth error"); + if (DBGLEVEL >= 1) Dbprintf("Auth error"); break; }; if (mifare_classic_readblock(pcs, cuid, blockNo, dataoutbuf)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Read block error"); + if (DBGLEVEL >= 1) Dbprintf("Read block error"); break; }; if (mifare_classic_halt(pcs, cuid)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Halt error"); + if (DBGLEVEL >= 1) Dbprintf("Halt error"); break; }; @@ -88,7 +88,7 @@ void MifareReadBlock(uint8_t blockNo, uint8_t keyType, uint8_t *datain) { crypto1_destroy(pcs); - if (MF_DBGLEVEL >= 2) DbpString("READ BLOCK FINISHED"); + if (DBGLEVEL >= 2) DbpString("READ BLOCK FINISHED"); LED_B_ON(); reply_ng(CMD_MIFARE_READBL, status, dataoutbuf, 16); @@ -112,13 +112,13 @@ void MifareUC_Auth(uint8_t arg0, uint8_t *keybytes) { set_tracing(true); if (!iso14443a_select_card(NULL, NULL, NULL, true, 0, true)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Can't select card"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card"); OnError(0); return; }; if (!mifare_ultra_auth(keybytes)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Authentication failed"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Authentication failed"); OnError(1); return; } @@ -148,7 +148,7 @@ void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) { int len = iso14443a_select_card(NULL, NULL, NULL, true, 0, true); if (!len) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Can't select card (RC:%02X)", len); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card (RC:%02X)", len); OnError(1); return; } @@ -176,13 +176,13 @@ void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) { } if (mifare_ultra_readblock(blockNo, dataout)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Read block error"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Read block error"); OnError(2); return; } if (mifare_ultra_halt()) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Halt error"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Halt error"); OnError(3); return; } @@ -224,28 +224,28 @@ void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t *datain) { isOK = 1; if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) { isOK = 0; - if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card"); + if (DBGLEVEL >= 1) Dbprintf("Can't select card"); } if (isOK && mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keyType, ui64Key, AUTH_FIRST)) { isOK = 0; - if (MF_DBGLEVEL >= 1) Dbprintf("Auth error"); + if (DBGLEVEL >= 1) Dbprintf("Auth error"); } for (uint8_t blockNo = 0; isOK && blockNo < NumBlocksPerSector(sectorNo); blockNo++) { if (mifare_classic_readblock(pcs, cuid, FirstBlockOfSector(sectorNo) + blockNo, dataoutbuf + 16 * blockNo)) { isOK = 0; - if (MF_DBGLEVEL >= 1) Dbprintf("Read sector %2d block %2d error", sectorNo, blockNo); + if (DBGLEVEL >= 1) Dbprintf("Read sector %2d block %2d error", sectorNo, blockNo); break; } } if (mifare_classic_halt(pcs, cuid)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Halt error"); + if (DBGLEVEL >= 1) Dbprintf("Halt error"); } - if (MF_DBGLEVEL >= 2) DbpString("READ SECTOR FINISHED"); + if (DBGLEVEL >= 2) DbpString("READ SECTOR FINISHED"); crypto1_destroy(pcs); @@ -288,7 +288,7 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain) int len = iso14443a_select_card(NULL, NULL, NULL, true, 0, true); if (!len) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Can't select card (RC:%d)", len); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card (RC:%d)", len); OnError(1); return; } @@ -325,7 +325,7 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain) len = mifare_ultra_readblock(blockNo + i, dataout + 4 * i); if (len) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Read block %d error", i); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Read block %d error", i); // if no blocks read - error out if (i == 0) { OnError(2); @@ -341,12 +341,12 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain) len = mifare_ultra_halt(); if (len) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Halt error"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Halt error"); OnError(3); return; } - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Blocks read %d", countblocks); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Blocks read %d", countblocks); countblocks *= 4; @@ -390,22 +390,22 @@ void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) { while (true) { if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card"); + if (DBGLEVEL >= 1) Dbprintf("Can't select card"); break; }; if (mifare_classic_auth(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Auth error"); + if (DBGLEVEL >= 1) Dbprintf("Auth error"); break; }; if (mifare_classic_writeblock(pcs, cuid, blockNo, blockdata)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Write block error"); + if (DBGLEVEL >= 1) Dbprintf("Write block error"); break; }; if (mifare_classic_halt(pcs, cuid)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Halt error"); + if (DBGLEVEL >= 1) Dbprintf("Halt error"); break; }; @@ -415,7 +415,7 @@ void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) { crypto1_destroy(pcs); - if (MF_DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED"); + if (DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED"); reply_mix(CMD_ACK, isOK, 0, 0, 0, 0); @@ -441,23 +441,23 @@ void MifareUWriteBlockCompat(uint8_t arg0, uint8_t *datain) iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); if(!iso14443a_select_card(uid, NULL, NULL, true, 0, true)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card"); + if (DBGLEVEL >= 1) Dbprintf("Can't select card"); OnError(0); return; }; if(mifare_ultra_writeblock_compat(blockNo, blockdata)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Write block error"); + if (DBGLEVEL >= 1) Dbprintf("Write block error"); OnError(0); return; }; if(mifare_ultra_halt()) { - if (MF_DBGLEVEL >= 1) Dbprintf("Halt error"); + if (DBGLEVEL >= 1) Dbprintf("Halt error"); OnError(0); return; }; - if (MF_DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED"); + if (DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED"); reply_mix(CMD_ACK,1,0,0,0,0); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); @@ -487,7 +487,7 @@ void MifareUWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) { set_tracing(true); if (!iso14443a_select_card(NULL, NULL, NULL, true, 0, true)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card"); + if (DBGLEVEL >= 1) Dbprintf("Can't select card"); OnError(0); return; }; @@ -515,18 +515,18 @@ void MifareUWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) { } if (mifare_ultra_writeblock(blockNo, blockdata)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Write block error"); + if (DBGLEVEL >= 1) Dbprintf("Write block error"); OnError(0); return; }; if (mifare_ultra_halt()) { - if (MF_DBGLEVEL >= 1) Dbprintf("Halt error"); + if (DBGLEVEL >= 1) Dbprintf("Halt error"); OnError(0); return; }; - if (MF_DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED"); + if (DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED"); reply_mix(CMD_ACK, 1, 0, 0, 0, 0); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); @@ -550,7 +550,7 @@ void MifareUSetPwd(uint8_t arg0, uint8_t *datain) { set_tracing(true); if (!iso14443a_select_card(NULL, NULL, NULL, true, 0, true)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card"); + if (DBGLEVEL >= 1) Dbprintf("Can't select card"); OnError(0); return; }; @@ -560,7 +560,7 @@ void MifareUSetPwd(uint8_t arg0, uint8_t *datain) { blockdata[2] = pwd[5]; blockdata[3] = pwd[4]; if (mifare_ultra_writeblock(44, blockdata)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Write block error"); + if (DBGLEVEL >= 1) Dbprintf("Write block error"); OnError(44); return; }; @@ -570,7 +570,7 @@ void MifareUSetPwd(uint8_t arg0, uint8_t *datain) { blockdata[2] = pwd[1]; blockdata[3] = pwd[0]; if (mifare_ultra_writeblock(45, blockdata)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Write block error"); + if (DBGLEVEL >= 1) Dbprintf("Write block error"); OnError(45); return; }; @@ -580,7 +580,7 @@ void MifareUSetPwd(uint8_t arg0, uint8_t *datain) { blockdata[2] = pwd[13]; blockdata[3] = pwd[12]; if (mifare_ultra_writeblock(46, blockdata)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Write block error"); + if (DBGLEVEL >= 1) Dbprintf("Write block error"); OnError(46); return; }; @@ -590,13 +590,13 @@ void MifareUSetPwd(uint8_t arg0, uint8_t *datain) { blockdata[2] = pwd[9]; blockdata[3] = pwd[8]; if (mifare_ultra_writeblock(47, blockdata)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Write block error"); + if (DBGLEVEL >= 1) Dbprintf("Write block error"); OnError(47); return; }; if (mifare_ultra_halt()) { - if (MF_DBGLEVEL >= 1) Dbprintf("Halt error"); + if (DBGLEVEL >= 1) Dbprintf("Halt error"); OnError(0); return; }; @@ -655,7 +655,7 @@ void MifareAcquireNonces(uint32_t arg0, uint32_t flags) { if (!have_uid) { // need a full select cycle to get the uid first iso14a_card_select_t card_info; if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) { - if (MF_DBGLEVEL >= 1) Dbprintf("AcquireNonces: Can't select card (ALL)"); + if (DBGLEVEL >= 1) Dbprintf("AcquireNonces: Can't select card (ALL)"); continue; } switch (card_info.uidlen) { @@ -674,7 +674,7 @@ void MifareAcquireNonces(uint32_t arg0, uint32_t flags) { have_uid = true; } else { // no need for anticollision. We can directly select the card if (!iso14443a_fast_select_card(uid, cascade_levels)) { - if (MF_DBGLEVEL >= 1) Dbprintf("AcquireNonces: Can't select card (UID)"); + if (DBGLEVEL >= 1) Dbprintf("AcquireNonces: Can't select card (UID)"); continue; } } @@ -689,7 +689,7 @@ void MifareAcquireNonces(uint32_t arg0, uint32_t flags) { CHK_TIMEOUT(); if (len != 4) { - if (MF_DBGLEVEL >= 2) Dbprintf("AcquireNonces: Auth1 error"); + if (DBGLEVEL >= 2) Dbprintf("AcquireNonces: Auth1 error"); continue; } @@ -707,7 +707,7 @@ void MifareAcquireNonces(uint32_t arg0, uint32_t flags) { reply_old(CMD_ACK, isOK, cuid, num_nonces - 1, buf, sizeof(buf)); LED_B_OFF(); - if (MF_DBGLEVEL >= 3) DbpString("AcquireNonces finished"); + if (DBGLEVEL >= 3) DbpString("AcquireNonces finished"); if (field_off) { FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); @@ -773,7 +773,7 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, if (!have_uid) { // need a full select cycle to get the uid first iso14a_card_select_t card_info; if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) { - if (MF_DBGLEVEL >= 1) Dbprintf("AcquireNonces: Can't select card (ALL)"); + if (DBGLEVEL >= 1) Dbprintf("AcquireNonces: Can't select card (ALL)"); continue; } switch (card_info.uidlen) { @@ -792,7 +792,7 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, have_uid = true; } else { // no need for anticollision. We can directly select the card if (!iso14443a_fast_select_card(uid, cascade_levels)) { - if (MF_DBGLEVEL >= 1) Dbprintf("AcquireNonces: Can't select card (UID)"); + if (DBGLEVEL >= 1) Dbprintf("AcquireNonces: Can't select card (UID)"); continue; } } @@ -802,7 +802,7 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, uint32_t nt1; if (mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST, &nt1, NULL)) { - if (MF_DBGLEVEL >= 1) Dbprintf("AcquireNonces: Auth1 error"); + if (DBGLEVEL >= 1) Dbprintf("AcquireNonces: Auth1 error"); continue; } @@ -813,7 +813,7 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, CHK_TIMEOUT(); if (len != 4) { - if (MF_DBGLEVEL >= 1) Dbprintf("AcquireNonces: Auth2 error len=%d", len); + if (DBGLEVEL >= 1) Dbprintf("AcquireNonces: Auth2 error len=%d", len); continue; } @@ -835,7 +835,7 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, reply_old(CMD_ACK, isOK, cuid, num_nonces, buf, sizeof(buf)); LED_B_OFF(); - if (MF_DBGLEVEL >= 3) DbpString("AcquireEncryptedNonces finished"); + if (DBGLEVEL >= 3) DbpString("AcquireEncryptedNonces finished"); if (field_off) { FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); @@ -912,27 +912,27 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) // prepare next select. No need to power down the card. if (mifare_classic_halt(pcs, cuid)) { - if (MF_DBGLEVEL >= 2) Dbprintf("Nested: Halt error"); + if (DBGLEVEL >= 2) Dbprintf("Nested: Halt error"); rtr--; continue; } if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) { - if (MF_DBGLEVEL >= 2) Dbprintf("Nested: Can't select card"); + if (DBGLEVEL >= 2) Dbprintf("Nested: Can't select card"); rtr--; continue; }; auth1_time = 0; if (mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST, &nt1, &auth1_time)) { - if (MF_DBGLEVEL >= 2) Dbprintf("Nested: Auth1 error"); + if (DBGLEVEL >= 2) Dbprintf("Nested: Auth1 error"); rtr--; continue; }; auth2_time = (delta_time) ? auth1_time + delta_time : 0; if (mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_NESTED, &nt2, &auth2_time)) { - if (MF_DBGLEVEL >= 2) Dbprintf("Nested: Auth2 error"); + if (DBGLEVEL >= 2) Dbprintf("Nested: Auth2 error"); rtr--; continue; }; @@ -951,7 +951,7 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) } else { delta_time = auth2_time - auth1_time + 32; // allow some slack for proper timing } - if (MF_DBGLEVEL >= 3) Dbprintf("Nested: calibrating... ntdist=%d", i); + if (DBGLEVEL >= 3) Dbprintf("Nested: calibrating... ntdist=%d", i); } else { unsuccessfull_tries++; if (unsuccessfull_tries > NESTED_MAX_TRIES) { // card isn't vulnerable to nested attack (random numbers are not predictable) @@ -962,7 +962,7 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) davg = (davg + (rtr - 1) / 2) / (rtr - 1); - 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); + if (DBGLEVEL >= 3) Dbprintf("rtr=%d isOK=%d min=%d max=%d avg=%d, delta_time=%d", rtr, isOK, dmin, dmax, davg, delta_time); dmin = davg - 2; dmax = davg + 2; @@ -981,18 +981,18 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) // prepare next select. No need to power down the card. if (mifare_classic_halt(pcs, cuid)) { - if (MF_DBGLEVEL >= 2) Dbprintf("Nested: Halt error"); + if (DBGLEVEL >= 2) Dbprintf("Nested: Halt error"); continue; } if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) { - if (MF_DBGLEVEL >= 2) Dbprintf("Nested: Can't select card"); + if (DBGLEVEL >= 2) Dbprintf("Nested: Can't select card"); continue; }; auth1_time = 0; if (mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST, &nt1, &auth1_time)) { - if (MF_DBGLEVEL >= 2) Dbprintf("Nested: Auth1 error"); + if (DBGLEVEL >= 2) Dbprintf("Nested: Auth1 error"); continue; }; @@ -1001,12 +1001,12 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) len = mifare_sendcmd_short(pcs, AUTH_NESTED, 0x60 + (targetKeyType & 0x01), targetBlockNo, receivedAnswer, par, &auth2_time); if (len != 4) { - if (MF_DBGLEVEL >= 2) Dbprintf("Nested: Auth2 error len=%d", len); + if (DBGLEVEL >= 2) Dbprintf("Nested: Auth2 error len=%d", len); continue; }; nt2 = bytes_to_num(receivedAnswer, 4); - if (MF_DBGLEVEL >= 3) Dbprintf("Nonce#%d: Testing nt1=%08x nt2enc=%08x nt2par=%02x", i + 1, nt1, nt2, par[0]); + if (DBGLEVEL >= 3) Dbprintf("Nonce#%d: Testing nt1=%08x nt2enc=%08x nt2par=%02x", i + 1, nt1, nt2, par[0]); // Parity validity check for (j = 0; j < 4; j++) { @@ -1021,7 +1021,7 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) if (valid_nonce(nttest, nt2, ks1, par_array)) { if (ncount > 0) { // we are only interested in disambiguous nonces, try again - if (MF_DBGLEVEL >= 3) Dbprintf("Nonce#%d: dismissed (ambigous), ntdist=%d", i + 1, j); + if (DBGLEVEL >= 3) Dbprintf("Nonce#%d: dismissed (ambigous), ntdist=%d", i + 1, j); target_nt[i] = 0; break; } @@ -1030,13 +1030,13 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) ncount++; if (i == 1 && target_nt[1] == target_nt[0]) { // we need two different nonces target_nt[i] = 0; - if (MF_DBGLEVEL >= 3) Dbprintf("Nonce#2: dismissed (= nonce#1), ntdist=%d", j); + if (DBGLEVEL >= 3) Dbprintf("Nonce#2: dismissed (= nonce#1), ntdist=%d", j); break; } - if (MF_DBGLEVEL >= 3) Dbprintf("Nonce#%d: valid, ntdist=%d", i + 1, j); + if (DBGLEVEL >= 3) Dbprintf("Nonce#%d: valid, ntdist=%d", i + 1, j); } } - if (target_nt[i] == 0 && j == dmax + 1 && MF_DBGLEVEL >= 3) Dbprintf("Nonce#%d: dismissed (all invalid)", i + 1); + if (target_nt[i] == 0 && j == dmax + 1 && DBGLEVEL >= 3) Dbprintf("Nonce#%d: dismissed (all invalid)", i + 1); } } @@ -1055,7 +1055,7 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) reply_mix(CMD_ACK, isOK, 0, targetBlockNo + (targetKeyType * 0x100), buf, sizeof(buf)); LED_B_OFF(); - if (MF_DBGLEVEL >= 3) DbpString("NESTED FINISHED"); + if (DBGLEVEL >= 3) DbpString("NESTED FINISHED"); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); LEDsoff(); @@ -1147,7 +1147,7 @@ void chkKey_scanA(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, ui found[(s * 2)] = 1; ++*foundkeys; - if (MF_DBGLEVEL >= 3) Dbprintf("ChkKeys_fast: Scan A found (%d)", c->block); + if (DBGLEVEL >= 3) Dbprintf("ChkKeys_fast: Scan A found (%d)", c->block); } } } @@ -1165,7 +1165,7 @@ void chkKey_scanB(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, ui found[(s * 2) + 1] = 1; ++*foundkeys; - if (MF_DBGLEVEL >= 3) Dbprintf("ChkKeys_fast: Scan B found (%d)", c->block); + if (DBGLEVEL >= 3) Dbprintf("ChkKeys_fast: Scan B found (%d)", c->block); } } } @@ -1190,7 +1190,7 @@ void chkKey_loopBonly(struct chk_t *c, struct sector_t *k_sector, uint8_t *found found[(s * 2) + 1] = 1; ++*foundkeys; - if (MF_DBGLEVEL >= 3) Dbprintf("ChkKeys_fast: Reading B found (%d)", c->block); + if (DBGLEVEL >= 3) Dbprintf("ChkKeys_fast: Reading B found (%d)", c->block); // try quick find all B? // assume: keys comes in groups. Find one B, test against all B. @@ -1281,7 +1281,7 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da iso14a_card_select_t card_info; if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) { - if (MF_DBGLEVEL >= 1) Dbprintf("ChkKeys_fast: Can't select card (ALL)"); + if (DBGLEVEL >= 1) Dbprintf("ChkKeys_fast: Can't select card (ALL)"); goto OUT; } @@ -1558,7 +1558,7 @@ void MifareChkKeys(uint8_t *datain) { if (!have_uid) { // need a full select cycle to get the uid first iso14a_card_select_t card_info; if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) { - if (MF_DBGLEVEL >= 1) Dbprintf("ChkKeys: Can't select card (ALL)"); + if (DBGLEVEL >= 1) Dbprintf("ChkKeys: Can't select card (ALL)"); --i; // try same key once again continue; } @@ -1578,7 +1578,7 @@ void MifareChkKeys(uint8_t *datain) { have_uid = true; } else { // no need for anticollision. We can directly select the card if (!iso14443a_select_card(uid, NULL, NULL, false, cascade_levels, true)) { - if (MF_DBGLEVEL >= 1) Dbprintf("ChkKeys: Can't select card (UID)"); + if (DBGLEVEL >= 1) Dbprintf("ChkKeys: Can't select card (UID)"); --i; // try same key once again continue; } @@ -1606,15 +1606,6 @@ void MifareChkKeys(uint8_t *datain) { crypto1_destroy(pcs); } -//----------------------------------------------------------------------------- -// MIFARE commands set debug level -// -//----------------------------------------------------------------------------- -void MifareSetDbgLvl(uint16_t arg0) { - MF_DBGLEVEL = arg0; - Dbprintf("Debug level: %d", MF_DBGLEVEL); -} - //----------------------------------------------------------------------------- // Work with emulator memory // @@ -1687,20 +1678,20 @@ int MifareECardLoad(uint32_t arg0, uint32_t arg1) { if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) { isOK = false; - if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card"); + if (DBGLEVEL >= 1) Dbprintf("Can't select card"); } for (uint8_t sectorNo = 0; isOK && sectorNo < numSectors; sectorNo++) { ui64Key = emlGetKey(sectorNo, keyType); if (sectorNo == 0) { if (isOK && mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keyType, ui64Key, AUTH_FIRST)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Sector[%2d]. Auth error", sectorNo); + if (DBGLEVEL >= 1) Dbprintf("Sector[%2d]. Auth error", sectorNo); break; } } else { if (isOK && mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keyType, ui64Key, AUTH_NESTED)) { isOK = false; - if (MF_DBGLEVEL >= 1) Dbprintf("Sector[%2d]. Auth nested error", sectorNo); + if (DBGLEVEL >= 1) Dbprintf("Sector[%2d]. Auth nested error", sectorNo); break; } } @@ -1708,7 +1699,7 @@ int MifareECardLoad(uint32_t arg0, uint32_t arg1) { for (uint8_t blockNo = 0; isOK && blockNo < NumBlocksPerSector(sectorNo); blockNo++) { if (isOK && mifare_classic_readblock(pcs, cuid, FirstBlockOfSector(sectorNo) + blockNo, dataoutbuf)) { isOK = false; - if (MF_DBGLEVEL >= 1) Dbprintf("Error reading sector %2d block %2d", sectorNo, blockNo); + if (DBGLEVEL >= 1) Dbprintf("Error reading sector %2d block %2d", sectorNo, blockNo); break; } if (isOK) { @@ -1725,7 +1716,7 @@ int MifareECardLoad(uint32_t arg0, uint32_t arg1) { } if (mifare_classic_halt(pcs, cuid)) - if (MF_DBGLEVEL >= 1) + if (DBGLEVEL >= 1) Dbprintf("Halt error"); // ----------------------------- crypto1 destroy @@ -1734,7 +1725,7 @@ int MifareECardLoad(uint32_t arg0, uint32_t arg1) { FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); LEDsoff(); - if (MF_DBGLEVEL >= 2) DbpString("EMUL FILL SECTORS FINISHED"); + if (DBGLEVEL >= 2) DbpString("EMUL FILL SECTORS FINISHED"); set_tracing(false); return (isOK) ? PM3_SUCCESS : PM3_EUNDEF; @@ -1790,7 +1781,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) { // read UID and return to client with write if (workFlags & MAGIC_UID) { if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Can't select card"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card"); errormsg = MAGIC_UID; } mifare_classic_halt_ex(NULL); @@ -1801,14 +1792,14 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) { if (workFlags & MAGIC_WIPE) { ReaderTransmitBitsPar(wupC1, 7, NULL, NULL); if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("wupC1 error"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("wupC1 error"); errormsg = MAGIC_WIPE; break; } ReaderTransmit(wipeC, sizeof(wipeC), NULL); if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("wipeC error"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("wipeC error"); errormsg = MAGIC_WIPE; break; } @@ -1820,7 +1811,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) { if (workFlags & MAGIC_WUPC) { ReaderTransmitBitsPar(wupC1, 7, NULL, NULL); if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("wupC1 error"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("wupC1 error"); errormsg = MAGIC_WUPC; break; } @@ -1828,7 +1819,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) { if (!is1b) { ReaderTransmit(wupC2, sizeof(wupC2), NULL); if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) { - if (MF_DBGLEVEL >= MF_DBG_INFO) Dbprintf("Assuming Magic Gen 1B tag. [wupC2 failed]"); + if (DBGLEVEL >= DBG_INFO) Dbprintf("Assuming Magic Gen 1B tag. [wupC2 failed]"); is1b = true; continue; } @@ -1836,7 +1827,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) { } if ((mifare_sendcmd_short(NULL, 0, ISO14443A_CMD_WRITEBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL) != 1) || (receivedAnswer[0] != 0x0a)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("write block send command error"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("write block send command error"); errormsg = 4; break; } @@ -1846,7 +1837,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) { ReaderTransmit(data, sizeof(data), NULL); if ((ReaderReceive(receivedAnswer, receivedAnswerPar) != 1) || (receivedAnswer[0] != 0x0a)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("write block send data error"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("write block send data error"); errormsg = 0; break; } @@ -1898,7 +1889,7 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) { if (workFlags & MAGIC_WUPC) { ReaderTransmitBitsPar(wupC1, 7, NULL, NULL); if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("wupC1 error"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("wupC1 error"); errormsg = MAGIC_WUPC; break; } @@ -1906,7 +1897,7 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) { if (!is1b) { ReaderTransmit(wupC2, sizeof(wupC2), NULL); if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) { - if (MF_DBGLEVEL >= MF_DBG_INFO) Dbprintf("Assuming Magic Gen 1B tag. [wupC2 failed]"); + if (DBGLEVEL >= DBG_INFO) Dbprintf("Assuming Magic Gen 1B tag. [wupC2 failed]"); is1b = true; continue; } @@ -1915,7 +1906,7 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) { // read block if ((mifare_sendcmd_short(NULL, 0, ISO14443A_CMD_READBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL) != 18)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("read block send command error"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("read block send command error"); errormsg = 0; break; } @@ -2040,22 +2031,22 @@ void MifareSetMod(uint8_t *datain) { while (true) { if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card"); + if (DBGLEVEL >= 1) Dbprintf("Can't select card"); break; } if (mifare_classic_auth(pcs, cuid, 0, 0, ui64Key, AUTH_FIRST)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Auth error"); + if (DBGLEVEL >= 1) Dbprintf("Auth error"); break; } if (((respLen = mifare_sendcmd_short(pcs, 1, 0x43, mod, receivedAnswer, receivedAnswerPar, NULL)) != 1) || (receivedAnswer[0] != 0x0a)) { - if (MF_DBGLEVEL >= 1) Dbprintf("SetMod error; response[0]: %hhX, len: %d", receivedAnswer[0], respLen); + if (DBGLEVEL >= 1) Dbprintf("SetMod error; response[0]: %hhX, len: %d", receivedAnswer[0], respLen); break; } if (mifare_classic_halt(pcs, cuid)) { - if (MF_DBGLEVEL >= 1) Dbprintf("Halt error"); + if (DBGLEVEL >= 1) Dbprintf("Halt error"); break; } @@ -2088,18 +2079,18 @@ void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain) { int len = iso14443a_select_card(uid, NULL, &cuid, true, 0, false); if (!len) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Can't select card"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card"); OnError(1); return; }; if (mifare_desfire_des_auth1(cuid, dataout)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Authentication part1: Fail."); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Authentication part1: Fail."); OnError(4); return; } - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) DbpString("AUTH 1 FINISHED"); + if (DBGLEVEL >= DBG_EXTENDED) DbpString("AUTH 1 FINISHED"); reply_mix(CMD_ACK, 1, cuid, 0, dataout, sizeof(dataout)); } @@ -2114,12 +2105,12 @@ void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain) { isOK = mifare_desfire_des_auth2(cuid, key, dataout); if (isOK) { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Authentication part2: Failed"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Authentication part2: Failed"); OnError(4); return; } - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) DbpString("AUTH 2 FINISHED"); + if (DBGLEVEL >= DBG_EXTENDED) DbpString("AUTH 2 FINISHED"); reply_old(CMD_ACK, isOK, 0, 0, dataout, sizeof(dataout)); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); diff --git a/armsrc/mifaredesfire.c b/armsrc/mifaredesfire.c index c152bcb9f..9cfb0492f 100644 --- a/armsrc/mifaredesfire.c +++ b/armsrc/mifaredesfire.c @@ -24,7 +24,7 @@ bool InitDesfireCard() { set_tracing(true); if (!iso14443a_select_card(NULL, &card, NULL, true, 0, false)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) DbpString("Can't select card"); + if (DBGLEVEL >= DBG_ERROR) DbpString("Can't select card"); OnError(1); return false; } @@ -52,7 +52,7 @@ void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain) { uint8_t resp[RECEIVE_SIZE]; memset(resp, 0, sizeof(resp)); - if (MF_DBGLEVEL >= 4) { + if (DBGLEVEL >= 4) { Dbprintf(" flags : %02X", flags); Dbprintf(" len : %02X", datalen); print_result(" RX : ", datain, datalen); @@ -67,7 +67,7 @@ void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain) { } int len = DesfireAPDU(datain, datalen, resp); - if (MF_DBGLEVEL >= 4) + if (DBGLEVEL >= 4) print_result("ERR <--: ", resp, len); if (!len) { @@ -106,13 +106,13 @@ void MifareDesfireGetInformation() { // card select - information if (!iso14443a_select_card(NULL, &card, NULL, true, 0, false)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) DbpString("Can't select card"); + if (DBGLEVEL >= DBG_ERROR) DbpString("Can't select card"); OnError(1); return; } if (card.uidlen != 7) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Wrong UID size. Expected 7byte got %d", card.uidlen); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Wrong UID size. Expected 7byte got %d", card.uidlen); OnError(2); return; } @@ -236,7 +236,7 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) cmd[1] = arg2; //keynumber len = DesfireAPDU(cmd, 2, resp); if (!len) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) { + if (DBGLEVEL >= DBG_ERROR) { DbpString("Authentication failed. Card timeout."); } OnError(3); @@ -288,7 +288,7 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) len = DesfireAPDU(cmd, 17, resp); if (!len) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) { + if (DBGLEVEL >= DBG_ERROR) { DbpString("Authentication failed. Card timeout."); } OnError(3); @@ -438,7 +438,7 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) AesCtx ctx; if (AesCtxIni(&ctx, IV, key->data, KEY128, CBC) < 0) { - if (MF_DBGLEVEL >= 4) { + if (DBGLEVEL >= 4) { DbpString("AES context failed to init"); } OnError(7); @@ -449,7 +449,7 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) cmd[1] = 0x00; //keynumber len = DesfireAPDU(cmd, 2, resp); if (!len) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) { + if (DBGLEVEL >= DBG_ERROR) { DbpString("Authentication failed. Card timeout."); } OnError(3); @@ -470,7 +470,7 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) len = DesfireAPDU(cmd, 33, resp); // 1 + 32 == 33 if (!len) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) { + if (DBGLEVEL >= DBG_ERROR) { DbpString("Authentication failed. Card timeout."); } OnError(3); @@ -511,14 +511,14 @@ int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout) { wrappedLen = CreateAPDU(cmd, cmd_len, wCmd); - if (MF_DBGLEVEL >= 4) + if (DBGLEVEL >= 4) print_result("WCMD <--: ", wCmd, wrappedLen); ReaderTransmit(wCmd, wrappedLen, NULL); len = ReaderReceive(resp, par); if (!len) { - if (MF_DBGLEVEL >= 4) Dbprintf("fukked"); + if (DBGLEVEL >= 4) Dbprintf("fukked"); return false; //DATA LINK ERROR } // if we received an I- or R(ACK)-Block with a block number equal to the diff --git a/armsrc/mifaresim.c b/armsrc/mifaresim.c index 8ad397ac3..5d83277fc 100644 --- a/armsrc/mifaresim.c +++ b/armsrc/mifaresim.c @@ -11,11 +11,11 @@ //----------------------------------------------------------------------------- // Verbose Mode: -// MF_DBG_NONE 0 -// MF_DBG_ERROR 1 -// MF_DBG_INFO 2 -// MF_DBG_DEBUG 3 -// MF_DBG_EXTENDED 4 +// DBG_NONE 0 +// DBG_ERROR 1 +// DBG_INFO 2 +// DBG_DEBUG 3 +// DBG_EXTENDED 4 // /!\ Printing Debug message is disrupting emulation, // Only use with caution during debugging @@ -42,30 +42,30 @@ static bool IsTrailerAccessAllowed(uint8_t blockNo, uint8_t keytype, uint8_t act | ((sector_trailer[8] >> 7) & 0x01); switch (action) { case AC_KEYA_READ: { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("IsTrailerAccessAllowed: AC_KEYA_READ"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("IsTrailerAccessAllowed: AC_KEYA_READ"); return false; } case AC_KEYA_WRITE: { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("IsTrailerAccessAllowed: AC_KEYA_WRITE"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("IsTrailerAccessAllowed: AC_KEYA_WRITE"); return ((keytype == AUTHKEYA && (AC == 0x00 || AC == 0x01)) || (keytype == AUTHKEYB && (AC == 0x04 || AC == 0x03))); } case AC_KEYB_READ: { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("IsTrailerAccessAllowed: AC_KEYB_READ"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("IsTrailerAccessAllowed: AC_KEYB_READ"); return (keytype == AUTHKEYA && (AC == 0x00 || AC == 0x02 || AC == 0x01)); } case AC_KEYB_WRITE: { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("IsTrailerAccessAllowed: AC_KEYB_WRITE"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("IsTrailerAccessAllowed: AC_KEYB_WRITE"); return ((keytype == AUTHKEYA && (AC == 0x00 || AC == 0x04)) || (keytype == AUTHKEYB && (AC == 0x04 || AC == 0x03))); } case AC_AC_READ: { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("IsTrailerAccessAllowed: AC_AC_READ"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("IsTrailerAccessAllowed: AC_AC_READ"); return ((keytype == AUTHKEYA) || (keytype == AUTHKEYB && !(AC == 0x00 || AC == 0x02 || AC == 0x01))); } case AC_AC_WRITE: { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("IsTrailerAccessAllowed: AC_AC_WRITE"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("IsTrailerAccessAllowed: AC_AC_WRITE"); return ((keytype == AUTHKEYA && (AC == 0x01)) || (keytype == AUTHKEYB && (AC == 0x03 || AC == 0x05))); } @@ -93,46 +93,46 @@ static bool IsDataAccessAllowed(uint8_t blockNo, uint8_t keytype, uint8_t action AC = ((sector_trailer[7] >> 2) & 0x04) | ((sector_trailer[8] << 1) & 0x02) | ((sector_trailer[8] >> 4) & 0x01); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("IsDataAccessAllowed: case 0x00 - %02x", AC); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("IsDataAccessAllowed: case 0x00 - %02x", AC); break; } case 0x01: { AC = ((sector_trailer[7] >> 3) & 0x04) | ((sector_trailer[8] >> 0) & 0x02) | ((sector_trailer[8] >> 5) & 0x01); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("IsDataAccessAllowed: case 0x01 - %02x", AC); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("IsDataAccessAllowed: case 0x01 - %02x", AC); break; } case 0x02: { AC = ((sector_trailer[7] >> 4) & 0x04) | ((sector_trailer[8] >> 1) & 0x02) | ((sector_trailer[8] >> 6) & 0x01); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("IsDataAccessAllowed: case 0x02 - %02x", AC); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("IsDataAccessAllowed: case 0x02 - %02x", AC); break; } default: - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("IsDataAccessAllowed: Error"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("IsDataAccessAllowed: Error"); return false; } switch (action) { case AC_DATA_READ: { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("IsDataAccessAllowed - AC_DATA_READ: OK"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("IsDataAccessAllowed - AC_DATA_READ: OK"); return ((keytype == AUTHKEYA && !(AC == 0x03 || AC == 0x05 || AC == 0x07)) || (keytype == AUTHKEYB && !(AC == 0x07))); } case AC_DATA_WRITE: { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("IsDataAccessAllowed - AC_DATA_WRITE: OK"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("IsDataAccessAllowed - AC_DATA_WRITE: OK"); return ((keytype == AUTHKEYA && (AC == 0x00)) || (keytype == AUTHKEYB && (AC == 0x00 || AC == 0x04 || AC == 0x06 || AC == 0x03))); } case AC_DATA_INC: { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("IsDataAccessAllowed - AC_DATA_INC: OK"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("IsDataAccessAllowed - AC_DATA_INC: OK"); return ((keytype == AUTHKEYA && (AC == 0x00)) || (keytype == AUTHKEYB && (AC == 0x00 || AC == 0x06))); } case AC_DATA_DEC_TRANS_REST: { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("AC_DATA_DEC_TRANS_REST: OK"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("AC_DATA_DEC_TRANS_REST: OK"); return ((keytype == AUTHKEYA && (AC == 0x00 || AC == 0x06 || AC == 0x01)) || (keytype == AUTHKEYB && (AC == 0x00 || AC == 0x06 || AC == 0x01))); } @@ -257,14 +257,14 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, tag_response_info_t * if ((flags & FLAG_4B_UID_IN_DATA) == FLAG_4B_UID_IN_DATA) { // get UID from datain memcpy(rUIDBCC1, datain, 4); *uid_len = 4; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("MifareSimInit - FLAG_4B_UID_IN_DATA => Get UID from datain: %02X - Flag: %02X - UIDBCC1: %02X", FLAG_4B_UID_IN_DATA, flags, rUIDBCC1); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("MifareSimInit - FLAG_4B_UID_IN_DATA => Get UID from datain: %02X - Flag: %02X - UIDBCC1: %02X", FLAG_4B_UID_IN_DATA, flags, rUIDBCC1); // save CUID *cuid = bytes_to_num(rUIDBCC1, 4); // BCC rUIDBCC1[4] = rUIDBCC1[0] ^ rUIDBCC1[1] ^ rUIDBCC1[2] ^ rUIDBCC1[3]; - if (MF_DBGLEVEL >= MF_DBG_NONE) { + if (DBGLEVEL >= DBG_NONE) { Dbprintf("4B UID: %02x%02x%02x%02x", rUIDBCC1[0], rUIDBCC1[1], rUIDBCC1[2], rUIDBCC1[3]); } @@ -275,7 +275,7 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, tag_response_info_t * memcpy(&rUIDBCC1[1], datain, 3); memcpy(rUIDBCC2, datain + 3, 4); *uid_len = 7; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("MifareSimInit - FLAG_7B_UID_IN_DATA => Get UID from datain: %02X - Flag: %02X - UIDBCC1: %02X", FLAG_7B_UID_IN_DATA, flags, rUIDBCC1); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("MifareSimInit - FLAG_7B_UID_IN_DATA => Get UID from datain: %02X - Flag: %02X - UIDBCC1: %02X", FLAG_7B_UID_IN_DATA, flags, rUIDBCC1); // save CUID *cuid = bytes_to_num(rUIDBCC2, 4); @@ -284,7 +284,7 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, tag_response_info_t * // BCC rUIDBCC1[4] = rUIDBCC1[0] ^ rUIDBCC1[1] ^ rUIDBCC1[2] ^ rUIDBCC1[3]; rUIDBCC2[4] = rUIDBCC2[0] ^ rUIDBCC2[1] ^ rUIDBCC2[2] ^ rUIDBCC2[3]; - if (MF_DBGLEVEL >= MF_DBG_NONE) { + if (DBGLEVEL >= DBG_NONE) { Dbprintf("7B UID: %02x %02x %02x %02x %02x %02x %02x", rUIDBCC1[1], rUIDBCC1[2], rUIDBCC1[3], rUIDBCC2[0], rUIDBCC2[1], rUIDBCC2[2], rUIDBCC2[3]); } @@ -297,7 +297,7 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, tag_response_info_t * memcpy(&rUIDBCC2[1], datain + 3, 3); memcpy(rUIDBCC3, datain + 6, 4); *uid_len = 10; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("MifareSimInit - FLAG_10B_UID_IN_DATA => Get UID from datain: %02X - Flag: %02X - UIDBCC1: %02X", FLAG_10B_UID_IN_DATA, flags, rUIDBCC1); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("MifareSimInit - FLAG_10B_UID_IN_DATA => Get UID from datain: %02X - Flag: %02X - UIDBCC1: %02X", FLAG_10B_UID_IN_DATA, flags, rUIDBCC1); // save CUID *cuid = bytes_to_num(rUIDBCC3, 4); @@ -309,7 +309,7 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, tag_response_info_t * rUIDBCC2[4] = rUIDBCC2[0] ^ rUIDBCC2[1] ^ rUIDBCC2[2] ^ rUIDBCC2[3]; rUIDBCC3[4] = rUIDBCC3[0] ^ rUIDBCC3[1] ^ rUIDBCC3[2] ^ rUIDBCC3[3]; - if (MF_DBGLEVEL >= MF_DBG_NONE) { + if (DBGLEVEL >= DBG_NONE) { Dbprintf("10B UID: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", rUIDBCC1[1], rUIDBCC1[2], rUIDBCC1[3], rUIDBCC2[1], rUIDBCC2[2], rUIDBCC2[3], @@ -522,18 +522,18 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { if (res == 2) { //Field is off! LEDsoff(); cardSTATE = MFEMUL_NOFIELD; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("cardSTATE = MFEMUL_NOFIELD"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("cardSTATE = MFEMUL_NOFIELD"); continue; } else if (res == 1) { // button pressed button_pushed = true; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Button pressed"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Button pressed"); break; } // WUPA in HALTED state or REQA or WUPA in any other state if (receivedCmd_len == 1 && ((receivedCmd[0] == ISO14443A_CMD_REQA && cardSTATE != MFEMUL_HALTED) || receivedCmd[0] == ISO14443A_CMD_WUPA)) { selTimer = GetTickCount(); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("EmSendPrecompiledCmd(&responses[ATQA]);"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("EmSendPrecompiledCmd(&responses[ATQA]);"); EmSendPrecompiledCmd(&responses[ATQA]); // init crypto block @@ -552,12 +552,12 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { switch (cardSTATE) { case MFEMUL_NOFIELD: - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("MFEMUL_NOFIELD"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("MFEMUL_NOFIELD"); case MFEMUL_HALTED: - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("MFEMUL_HALTED"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("MFEMUL_HALTED"); case MFEMUL_IDLE: { LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("MFEMUL_IDLE"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("MFEMUL_IDLE"); break; } @@ -591,14 +591,14 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { if (uid_index < 0) { LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true); cardSTATE_TO_IDLE(); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] Incorrect cascade level received"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] Incorrect cascade level received"); break; } // Incoming SELECT ALL for any cascade level if (receivedCmd_len == 2 && receivedCmd[1] == 0x20) { EmSendPrecompiledCmd(&responses[uid_index]); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("SELECT ALL - EmSendPrecompiledCmd(%02x)", &responses[uid_index]); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("SELECT ALL - EmSendPrecompiledCmd(%02x)", &responses[uid_index]); break; } @@ -609,17 +609,17 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { (uid_len == 7 && uid_index == UIDBCC2) || (uid_len == 10 && uid_index == UIDBCC3); EmSendPrecompiledCmd(&responses[finished ? SAK : SAKuid]); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("SELECT CLx %02x%02x%02x%02x received", receivedCmd[2], receivedCmd[3], receivedCmd[4], receivedCmd[5]); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("SELECT CLx %02x%02x%02x%02x received", receivedCmd[2], receivedCmd[3], receivedCmd[4], receivedCmd[5]); if (finished) { LED_B_ON(); cardSTATE = MFEMUL_WORK; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] cardSTATE = MFEMUL_WORK"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] cardSTATE = MFEMUL_WORK"); } } else { // IDLE, not our UID LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true); cardSTATE_TO_IDLE(); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] cardSTATE = MFEMUL_IDLE"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] cardSTATE = MFEMUL_IDLE"); } break; } @@ -630,12 +630,12 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { if (memcmp(&receivedCmd[2], responses[uid_index].response, receivedCmd_len - 2) == 0) { // response missing part of UID via relative array index EmSendPrecompiledCmd(&responses[uid_index + receivedCmd_len - 2]); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("SELECT ANTICOLLISION - EmSendPrecompiledCmd(%02x)", &responses[uid_index]); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("SELECT ANTICOLLISION - EmSendPrecompiledCmd(%02x)", &responses[uid_index]); } else { // IDLE, not our UID or split-byte frame anti-collision (not supports) LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true); cardSTATE_TO_IDLE(); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] cardSTATE = MFEMUL_IDLE"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] cardSTATE = MFEMUL_IDLE"); } break; } @@ -643,17 +643,17 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { // Unknown selection procedure LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true); cardSTATE_TO_IDLE(); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] Unknown selection procedure"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] Unknown selection procedure"); break; } // WORK case MFEMUL_WORK: { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Enter in case"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Enter in case"); if (receivedCmd_len == 0) { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] NO CMD received"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] NO CMD received"); break; } @@ -661,7 +661,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { if (encrypted_data) { // decrypt seqence mf_crypto1_decryptEx(pcs, receivedCmd, receivedCmd_len, receivedCmd_dec); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Decrypt seqence"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Decrypt seqence"); } else { // Data in clear memcpy(receivedCmd_dec, receivedCmd, receivedCmd_len); @@ -669,7 +669,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { if (!CheckCrc14A(receivedCmd_dec, receivedCmd_len)) { // all commands must have a valid CRC EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] All commands must have a valid CRC %02X (%d)", receivedCmd_dec, receivedCmd_len); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] All commands must have a valid CRC %02X (%d)", receivedCmd_dec, receivedCmd_len); break; } @@ -683,7 +683,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { // if authenticating to a block that shouldn't exist - as long as we are not doing the reader attack if (receivedCmd_dec[1] > MIFARE_4K_MAXBLOCK && !((flags & FLAG_NR_AR_ATTACK) == FLAG_NR_AR_ATTACK)) { EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA)); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Reader tried to operate (0x%02x) on out of range block: %d (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], receivedCmd_dec[1]); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Reader tried to operate (0x%02x) on out of range block: %d (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], receivedCmd_dec[1]); break; } @@ -698,7 +698,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { // cardAUTHKEY: 61 => Auth use Key B cardAUTHKEY = receivedCmd_dec[0] & 0x01; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] KEY %c: %012" PRIx64, (cardAUTHKEY == 0) ? 'A' : 'B', emlGetKey(cardAUTHSC, cardAUTHKEY)); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] KEY %c: %012" PRIx64, (cardAUTHKEY == 0) ? 'A' : 'B', emlGetKey(cardAUTHSC, cardAUTHKEY)); // first authentication crypto1_destroy(pcs); @@ -712,7 +712,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { crypto1_word(pcs, cuid ^ nonce, 0); // rAUTH_NT contains prepared nonce for authenticate EmSendCmd(rAUTH_NT, sizeof(rAUTH_NT)); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Reader authenticating for block %d (0x%02x) with key %c - nonce: %02X - ciud: %02X", receivedCmd_dec[1], receivedCmd_dec[1], (cardAUTHKEY == 0) ? 'A' : 'B', rAUTH_AT, cuid); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Reader authenticating for block %d (0x%02x) with key %c - nonce: %02X - ciud: %02X", receivedCmd_dec[1], receivedCmd_dec[1], (cardAUTHKEY == 0) ? 'A' : 'B', rAUTH_AT, cuid); } else { // nested authentication /* @@ -723,11 +723,11 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { // we need calculate parity bits for non-encrypted sequence mf_crypto1_encryptEx(pcs, rAUTH_NT, rAUTH_NT_keystream, response, 4, response_par); EmSendCmdPar(response, 4, response_par); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Reader doing nested authentication for block %d (0x%02x) with key %c", receivedCmd_dec[1], receivedCmd_dec[1], (cardAUTHKEY == 0) ? 'A' : 'B'); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Reader doing nested authentication for block %d (0x%02x) with key %c", receivedCmd_dec[1], receivedCmd_dec[1], (cardAUTHKEY == 0) ? 'A' : 'B'); } cardSTATE = MFEMUL_AUTH1; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_AUTH1 - rAUTH_NT: %02X", rAUTH_NT); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_AUTH1 - rAUTH_NT: %02X", rAUTH_NT); break; } @@ -754,18 +754,18 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { // all other commands must be encrypted (authenticated) if (!encrypted_data) { EmSend4bit(CARD_NACK_NA); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Commands must be encrypted (authenticated)"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Commands must be encrypted (authenticated)"); break; } // Check if Block num is not too far if (receivedCmd_dec[1] > MIFARE_4K_MAXBLOCK) { EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA)); - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("[MFEMUL_WORK] Reader tried to operate (0x%02x) on out of range block: %d (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], receivedCmd_dec[1]); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("[MFEMUL_WORK] Reader tried to operate (0x%02x) on out of range block: %d (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], receivedCmd_dec[1]); break; } if (MifareBlockToSector(receivedCmd_dec[1]) != cardAUTHSC) { EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA)); - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("[MFEMUL_WORK] Reader tried to operate (0x%02x) on block (0x%02x) not authenticated for (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], cardAUTHSC); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("[MFEMUL_WORK] Reader tried to operate (0x%02x) on block (0x%02x) not authenticated for (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], cardAUTHSC); break; } } @@ -773,9 +773,9 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { // case MFEMUL_WORK => CMD READ block if (receivedCmd_len == 4 && receivedCmd_dec[0] == ISO14443A_CMD_READBLOCK) { blockNo = receivedCmd_dec[1]; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Reader reading block %d (0x%02x)", blockNo, blockNo); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Reader reading block %d (0x%02x)", blockNo, blockNo); emlGetMem(response, blockNo, 1); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { Dbprintf("[MFEMUL_WORK - ISO14443A_CMD_READBLOCK] Data Block[%d]: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", blockNo, response[0], response[1], response[2], response[3], response[4], response[5], response[6], response[7], response[8], response[9], response[10], response[11], response[12], response[13], @@ -801,26 +801,26 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { if (!IsAccessAllowed(blockNo, cardAUTHKEY, AC_KEYA_READ)) { memset(response, 0x00, 6); // keyA can never be read - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsSectorTrailer] keyA can never be read - block %d (0x%02x)", blockNo, blockNo); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsSectorTrailer] keyA can never be read - block %d (0x%02x)", blockNo, blockNo); } if (!IsAccessAllowed(blockNo, cardAUTHKEY, AC_KEYB_READ)) { memset(response + 10, 0x00, 6); // keyB cannot be read - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsSectorTrailer] keyB cannot be read - block %d (0x%02x)", blockNo, blockNo); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsSectorTrailer] keyB cannot be read - block %d (0x%02x)", blockNo, blockNo); } if (!IsAccessAllowed(blockNo, cardAUTHKEY, AC_AC_READ)) { memset(response + 6, 0x00, 4); // AC bits cannot be read - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsAccessAllowed] AC bits cannot be read - block %d (0x%02x)", blockNo, blockNo); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsAccessAllowed] AC bits cannot be read - block %d (0x%02x)", blockNo, blockNo); } } else { if (!IsAccessAllowed(blockNo, cardAUTHKEY, AC_DATA_READ)) { memset(response, 0x00, 16); // datablock cannot be read - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsAccessAllowed] Data block %d (0x%02x) cannot be read", blockNo, blockNo); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsAccessAllowed] Data block %d (0x%02x) cannot be read", blockNo, blockNo); } } AddCrc14A(response, 16); mf_crypto1_encrypt(pcs, response, MAX_MIFARE_FRAME_SIZE, response_par); EmSendCmdPar(response, MAX_MIFARE_FRAME_SIZE, response_par); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { Dbprintf("[MFEMUL_WORK - EmSendCmdPar] Data Block[%d]: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", blockNo, response[0], response[1], response[2], response[3], response[4], response[5], response[6], response[7], response[8], response[9], response[10], response[11], response[12], response[13], @@ -839,20 +839,20 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { // case MFEMUL_WORK => CMD WRITEBLOCK if (receivedCmd_len == 4 && receivedCmd_dec[0] == ISO14443A_CMD_WRITEBLOCK) { blockNo = receivedCmd_dec[1]; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RECV 0xA0 write block %d (%02x)", blockNo, blockNo); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RECV 0xA0 write block %d (%02x)", blockNo, blockNo); EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_ACK)); cardWRBL = blockNo; cardSTATE = MFEMUL_WRITEBL2; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_WRITEBL2"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_WRITEBL2"); break; } // case MFEMUL_WORK => CMD INC/DEC/REST if (receivedCmd_len == 4 && (receivedCmd_dec[0] == MIFARE_CMD_INC || receivedCmd_dec[0] == MIFARE_CMD_DEC || receivedCmd_dec[0] == MIFARE_CMD_RESTORE)) { blockNo = receivedCmd_dec[1]; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RECV 0x%02x inc(0xC1)/dec(0xC0)/restore(0xC2) block %d (%02x)", receivedCmd_dec[0], blockNo, blockNo); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RECV 0x%02x inc(0xC1)/dec(0xC0)/restore(0xC2) block %d (%02x)", receivedCmd_dec[0], blockNo, blockNo); if (emlCheckValBl(blockNo)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("[MFEMUL_WORK] Reader tried to operate on block, but emlCheckValBl failed, nacking"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("[MFEMUL_WORK] Reader tried to operate on block, but emlCheckValBl failed, nacking"); EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA)); break; } @@ -862,19 +862,19 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { // INC if (receivedCmd_dec[0] == MIFARE_CMD_INC) { cardSTATE = MFEMUL_INTREG_INC; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_INTREG_INC"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_INTREG_INC"); } // DEC if (receivedCmd_dec[0] == MIFARE_CMD_DEC) { cardSTATE = MFEMUL_INTREG_DEC; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_INTREG_DEC"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_INTREG_DEC"); } // REST if (receivedCmd_dec[0] == MIFARE_CMD_RESTORE) { cardSTATE = MFEMUL_INTREG_REST; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_INTREG_REST"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_INTREG_REST"); } break; @@ -884,7 +884,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { // case MFEMUL_WORK => CMD TRANSFER if (receivedCmd_len == 4 && receivedCmd_dec[0] == MIFARE_CMD_TRANSFER) { blockNo = receivedCmd_dec[1]; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RECV 0x%02x transfer block %d (%02x)", receivedCmd_dec[0], blockNo, blockNo); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RECV 0x%02x transfer block %d (%02x)", receivedCmd_dec[0], blockNo, blockNo); if (emlSetValBl(cardINTREG, cardINTBLOCK, receivedCmd_dec[1])) EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA)); else @@ -899,7 +899,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { LED_C_OFF(); cardSTATE = MFEMUL_HALTED; cardAUTHKEY = AUTHKEYNONE; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_HALTED"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_HALTED"); break; } @@ -912,10 +912,10 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { EmSendCmdPar(response, rats_len, response_par); } else EmSendCmd(rats, rats_len); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RCV RATS => ACK"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RCV RATS => ACK"); } else { EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RCV RATS => NACK"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RCV RATS => NACK"); } break; } @@ -930,28 +930,28 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { EmSendCmdPar(response, receivedCmd_len, response_par); } else EmSendCmd(receivedCmd_dec, receivedCmd_len); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RCV NXP DESELECT => ACK"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RCV NXP DESELECT => ACK"); } else { EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RCV NXP DESELECT => NACK"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RCV NXP DESELECT => NACK"); } break; } // case MFEMUL_WORK => command not allowed - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Received command not allowed, nacking"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Received command not allowed, nacking"); EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA); break; } // AUTH1 case MFEMUL_AUTH1: { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_AUTH1] Enter case"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_AUTH1] Enter case"); if (receivedCmd_len != 8) { cardSTATE_TO_IDLE(); LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("MFEMUL_AUTH1: receivedCmd_len != 8 (%d) => cardSTATE_TO_IDLE())", receivedCmd_len); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("MFEMUL_AUTH1: receivedCmd_len != 8 (%d) => cardSTATE_TO_IDLE())", receivedCmd_len); break; } @@ -1025,7 +1025,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { // test if auth KO if (cardRr != prng_successor(nonce, 64)) { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { Dbprintf("[MFEMUL_AUTH1] AUTH FAILED for sector %d with key %c. [nr=%08x cardRr=%08x] [nt=%08x succ=%08x]" , cardAUTHSC , (cardAUTHKEY == 0) ? 'A' : 'B' @@ -1046,7 +1046,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { mf_crypto1_encrypt(pcs, rAUTH_AT, 4, response_par); EmSendCmdPar(rAUTH_AT, 4, response_par); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { Dbprintf("[MFEMUL_AUTH1] AUTH COMPLETED for sector %d with key %c. time=%d", cardAUTHSC, cardAUTHKEY == 0 ? 'A' : 'B', @@ -1055,7 +1055,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { } LED_C_ON(); cardSTATE = MFEMUL_WORK; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_AUTH1] cardSTATE = MFEMUL_WORK"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_AUTH1] cardSTATE = MFEMUL_WORK"); break; } @@ -1083,12 +1083,12 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { emlSetMem(receivedCmd_dec, cardWRBL, 1); EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_ACK)); // always ACK? cardSTATE = MFEMUL_WORK; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WRITEBL2] cardSTATE = MFEMUL_WORK"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WRITEBL2] cardSTATE = MFEMUL_WORK"); break; } } cardSTATE_TO_IDLE(); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WRITEBL2] cardSTATE = MFEMUL_IDLE"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WRITEBL2] cardSTATE = MFEMUL_IDLE"); LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true); break; } @@ -1106,7 +1106,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { cardINTREG = cardINTREG + ans; cardSTATE = MFEMUL_WORK; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_INTREG_INC] cardSTATE = MFEMUL_WORK"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_INTREG_INC] cardSTATE = MFEMUL_WORK"); break; } } @@ -1125,7 +1125,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true); cardINTREG = cardINTREG - ans; cardSTATE = MFEMUL_WORK; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_INTREG_DEC] cardSTATE = MFEMUL_WORK"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_INTREG_DEC] cardSTATE = MFEMUL_WORK"); break; } @@ -1139,7 +1139,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { } LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true); cardSTATE = MFEMUL_WORK; - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_INTREG_REST] cardSTATE = MFEMUL_WORK"); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_INTREG_REST] cardSTATE = MFEMUL_WORK"); break; } @@ -1151,7 +1151,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { // NR AR ATTACK - if (((flags & FLAG_NR_AR_ATTACK) == FLAG_NR_AR_ATTACK) && (MF_DBGLEVEL >= MF_DBG_INFO)) { + if (((flags & FLAG_NR_AR_ATTACK) == FLAG_NR_AR_ATTACK) && (DBGLEVEL >= DBG_INFO)) { for (uint8_t i = 0; i < ATTACK_KEY_COUNT; i++) { if (ar_nr_collected[i] == 2) { Dbprintf("Collected two pairs of AR/NR which can be used to extract %s from reader for sector %d:", (i < ATTACK_KEY_COUNT / 2) ? "keyA" : "keyB", ar_nr_resp[i].sector); @@ -1182,7 +1182,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { } } - if (MF_DBGLEVEL >= MF_DBG_ERROR) { + if (DBGLEVEL >= DBG_ERROR) { Dbprintf("Emulator stopped. Tracing: %d trace length: %d ", get_tracing(), BigBuf_get_traceLen()); } diff --git a/armsrc/mifaresniff.c b/armsrc/mifaresniff.c index 790614c01..0c69c0381 100644 --- a/armsrc/mifaresniff.c +++ b/armsrc/mifaresniff.c @@ -76,7 +76,7 @@ void RAMFUNC SniffMifare(uint8_t param) { // Setup and start DMA. // set transfer address and number of bytes. Start transfer. if (!FpgaSetupSscDma(dmaBuf, DMA_BUFFER_SIZE)) { - if (MF_DBGLEVEL > 1) Dbprintf("[!] FpgaSetupSscDma failed. Exiting"); + if (DBGLEVEL > 1) Dbprintf("[!] FpgaSetupSscDma failed. Exiting"); return; } diff --git a/armsrc/mifareutil.c b/armsrc/mifareutil.c index 18c710733..6142198a5 100644 --- a/armsrc/mifareutil.c +++ b/armsrc/mifareutil.c @@ -9,7 +9,7 @@ //----------------------------------------------------------------------------- #include "mifareutil.h" -int MF_DBGLEVEL = MF_DBG_ERROR; +int DBGLEVEL = DBG_ERROR; // crypto1 helpers void mf_crypto1_decryptEx(struct Crypto1State *pcs, uint8_t *data_in, int len, uint8_t *data_out) { @@ -66,7 +66,7 @@ int mifare_sendcmd(uint8_t cmd, uint8_t *data, uint8_t data_size, uint8_t *answe ReaderTransmit(dcmd, sizeof(dcmd), timing); int len = ReaderReceive(answer, answer_parity); if (!len) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("%02X Cmd failed. Card timeout.", cmd); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("%02X Cmd failed. Card timeout.", cmd); len = ReaderReceive(answer, answer_parity); } return len; @@ -152,7 +152,7 @@ int mifare_classic_authex(struct Crypto1State *pcs, uint32_t uid, uint8_t blockN } // some statistic - if (!ntptr && (MF_DBGLEVEL >= MF_DBG_EXTENDED)) + if (!ntptr && (DBGLEVEL >= DBG_EXTENDED)) Dbprintf("auth uid: %08x | nr: %08x | nt: %08x", uid, nr, nt); // save Nt @@ -182,14 +182,14 @@ int mifare_classic_authex(struct Crypto1State *pcs, uint32_t uid, uint8_t blockN // Receive 4 byte tag answer len = ReaderReceive(receivedAnswer, receivedAnswerPar); if (!len) { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Authentication failed. Card timeout."); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Authentication failed. Card timeout."); return 2; } ntpp = prng_successor(nt, 32) ^ crypto1_word(pcs, 0, 0); if (ntpp != bytes_to_num(receivedAnswer, 4)) { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Authentication failed. Error card response."); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Authentication failed. Error card response."); return 3; } return 0; @@ -204,18 +204,18 @@ int mifare_classic_readblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blo len = mifare_sendcmd_short(pcs, 1, ISO14443A_CMD_READBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL); if (len == 1) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Cmd Error: %02x", receivedAnswer[0]); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Error: %02x", receivedAnswer[0]); return 1; } if (len != 18) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Cmd Error: wrong response len: %x (expected 18)", len); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Error: wrong response len: %x (expected 18)", len); return 2; } memcpy(bt, receivedAnswer + 16, 2); AddCrc14A(receivedAnswer, 16); if (bt[0] != receivedAnswer[16] || bt[1] != receivedAnswer[17]) { - if (MF_DBGLEVEL >= MF_DBG_INFO) Dbprintf("Cmd CRC response error."); + if (DBGLEVEL >= DBG_INFO) Dbprintf("Cmd CRC response error."); return 3; } @@ -232,17 +232,17 @@ int mifare_ul_ev1_auth(uint8_t *keybytes, uint8_t *pack) { uint8_t key[4] = {0x00, 0x00, 0x00, 0x00}; memcpy(key, keybytes, 4); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("EV1 Auth : %02x%02x%02x%02x", key[0], key[1], key[2], key[3]); len = mifare_sendcmd(MIFARE_ULEV1_AUTH, key, sizeof(key), resp, respPar, NULL); if (len != 4) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Cmd Error: %02x %u", resp[0], len); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Error: %02x %u", resp[0], len); return 0; } - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Auth Resp: %02x%02x%02x%02x", resp[0], resp[1], resp[2], resp[3]); memcpy(pack, resp, 4); @@ -267,7 +267,7 @@ int mifare_ultra_auth(uint8_t *keybytes) { // REQUEST AUTHENTICATION len = mifare_sendcmd_short(NULL, 1, MIFARE_ULC_AUTH_1, 0x00, resp, respPar, NULL); if (len != 11) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Cmd Error: %02x", resp[0]); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Error: %02x", resp[0]); return 0; } @@ -280,7 +280,7 @@ int mifare_ultra_auth(uint8_t *keybytes) { memcpy(rnd_ab, random_a, 8); memcpy(rnd_ab + 8, random_b, 8); - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { Dbprintf("enc_B: %02x %02x %02x %02x %02x %02x %02x %02x", enc_random_b[0], enc_random_b[1], enc_random_b[2], enc_random_b[3], enc_random_b[4], enc_random_b[5], enc_random_b[6], enc_random_b[7]); @@ -299,7 +299,7 @@ int mifare_ultra_auth(uint8_t *keybytes) { len = mifare_sendcmd(MIFARE_ULC_AUTH_2, rnd_ab, sizeof(rnd_ab), resp, respPar, NULL); if (len != 11) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Cmd Error: %02x", resp[0]); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Error: %02x", resp[0]); return 0; } @@ -310,11 +310,11 @@ int mifare_ultra_auth(uint8_t *keybytes) { // decrypt out, in, length, key, iv tdes_2key_dec(resp_random_a, enc_resp, 8, key, enc_random_b); if (memcmp(resp_random_a, random_a, 8) != 0) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("failed authentication"); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("failed authentication"); return 0; } - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { Dbprintf("e_AB: %02x %02x %02x %02x %02x %02x %02x %02x", rnd_ab[0], rnd_ab[1], rnd_ab[2], rnd_ab[3], rnd_ab[4], rnd_ab[5], rnd_ab[6], rnd_ab[7]); @@ -342,18 +342,18 @@ int mifare_ultra_readblockEx(uint8_t blockNo, uint8_t *blockData) { len = mifare_sendcmd_short(NULL, 1, ISO14443A_CMD_READBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL); if (len == 1) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Cmd Error: %02x", receivedAnswer[0]); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Error: %02x", receivedAnswer[0]); return 1; } if (len != 18) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Cmd Error: card timeout. len: %x", len); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Error: card timeout. len: %x", len); return 2; } memcpy(bt, receivedAnswer + 16, 2); AddCrc14A(receivedAnswer, 16); if (bt[0] != receivedAnswer[16] || bt[1] != receivedAnswer[17]) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Cmd CRC response error."); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd CRC response error."); return 3; } @@ -394,7 +394,7 @@ int mifare_classic_writeblock(struct Crypto1State *pcs, uint32_t uid, uint8_t bl len = mifare_sendcmd_short(pcs, 1, ISO14443A_CMD_WRITEBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL); if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Cmd Error: %02x", receivedAnswer[0]); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Error: %02x", receivedAnswer[0]); return 1; } @@ -419,7 +419,7 @@ int mifare_classic_writeblock(struct Crypto1State *pcs, uint32_t uid, uint8_t bl res |= (crypto1_bit(pcs, 0, 0) ^ BIT(receivedAnswer[0], 3)) << 3; if ((len != 1) || (res != 0x0A)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Cmd send data2 Error: %02x", res); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd send data2 Error: %02x", res); return 2; } return 0; @@ -436,7 +436,7 @@ int mifare_ultra_writeblock_compat(uint8_t blockNo, uint8_t *blockData) { len = mifare_sendcmd_short(NULL, true, ISO14443A_CMD_WRITEBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL); if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK - if (MF_DBGLEVEL >= MF_DBG_ERROR) + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Addr Error: %02x", receivedAnswer[0]); return 1; } @@ -449,7 +449,7 @@ int mifare_ultra_writeblock_compat(uint8_t blockNo, uint8_t *blockData) { len = ReaderReceive(receivedAnswer, receivedAnswerPar); if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK - if (MF_DBGLEVEL >= MF_DBG_ERROR) + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Data Error: %02x %d", receivedAnswer[0],len); return 2; } @@ -469,7 +469,7 @@ int mifare_ultra_writeblock(uint8_t blockNo, uint8_t *blockData) { len = mifare_sendcmd(MIFARE_ULC_WRITE, block, sizeof(block), receivedAnswer, receivedAnswerPar, NULL); if (receivedAnswer[0] != 0x0A) { // 0x0a - ACK - if (MF_DBGLEVEL >= MF_DBG_ERROR) + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Send Error: %02x %d", receivedAnswer[0], len); return 1; } @@ -479,7 +479,7 @@ int mifare_classic_halt_ex(struct Crypto1State *pcs) { uint8_t receivedAnswer[4] = {0x00, 0x00, 0x00, 0x00}; uint16_t len = mifare_sendcmd_short(pcs, (pcs == NULL) ? CRYPT_NONE : CRYPT_ALL, ISO14443A_CMD_HALT, 0x00, receivedAnswer, NULL, NULL); if (len != 0) { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("halt warning. response len: %x", len); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("halt warning. response len: %x", len); return 1; } return 0; @@ -493,7 +493,7 @@ int mifare_ultra_halt() { uint8_t receivedAnswer[4] = {0x00, 0x00, 0x00, 0x00}; len = mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_HALT, 0x00, receivedAnswer, NULL, NULL); if (len != 0) { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("halt warning. response len: %x", len); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("halt warning. response len: %x", len); return 1; } return 0; @@ -602,10 +602,10 @@ void emlClearMem(void) { uint8_t SectorTrailer(uint8_t blockNo) { if (blockNo <= MIFARE_2K_MAXBLOCK) { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Sector Trailer for block %d : %d", blockNo, (blockNo | 0x03)); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Sector Trailer for block %d : %d", blockNo, (blockNo | 0x03)); return (blockNo | 0x03); } else { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Sector Trailer for block %d : %d", blockNo, (blockNo | 0x0f)); + if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Sector Trailer for block %d : %d", blockNo, (blockNo | 0x0f)); return (blockNo | 0x0f); } } @@ -622,7 +622,7 @@ int mifare_sendcmd_special(struct Crypto1State *pcs, uint8_t crypted, uint8_t cm ReaderTransmit(dcmd, sizeof(dcmd), NULL); int len = ReaderReceive(answer, answer_parity); if (!len) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Authentication failed. Card timeout."); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Authentication failed. Card timeout."); return 1; } return len; @@ -637,7 +637,7 @@ int mifare_sendcmd_special2(struct Crypto1State *pcs, uint8_t crypted, uint8_t c ReaderTransmit(dcmd, sizeof(dcmd), NULL); int len = ReaderReceive(answer, answer_parity); if (!len) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Authentication failed. Card timeout."); + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Authentication failed. Card timeout."); return 1; } return len; @@ -653,13 +653,13 @@ int mifare_desfire_des_auth1(uint32_t uid, uint8_t *blockData) { len = mifare_sendcmd_special(NULL, 1, 0x02, data, receivedAnswer, receivedAnswerPar, NULL); if (len == 1) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Error: %02x", receivedAnswer[0]); return 1; } if (len == 12) { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { Dbprintf("Auth1 Resp: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", receivedAnswer[0], receivedAnswer[1], receivedAnswer[2], receivedAnswer[3], receivedAnswer[4], receivedAnswer[5], receivedAnswer[6], receivedAnswer[7], receivedAnswer[8], receivedAnswer[9], @@ -683,13 +683,13 @@ int mifare_desfire_des_auth2(uint32_t uid, uint8_t *key, uint8_t *blockData) { len = mifare_sendcmd_special2(NULL, 1, 0x03, data, receivedAnswer, receivedAnswerPar, NULL); if ((receivedAnswer[0] == 0x03) && (receivedAnswer[1] == 0xae)) { - if (MF_DBGLEVEL >= MF_DBG_ERROR) + if (DBGLEVEL >= DBG_ERROR) Dbprintf("Auth Error: %02x %02x", receivedAnswer[0], receivedAnswer[1]); return 1; } if (len == 12) { - if (MF_DBGLEVEL >= MF_DBG_EXTENDED) { + if (DBGLEVEL >= DBG_EXTENDED) { Dbprintf("Auth2 Resp: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", receivedAnswer[0], receivedAnswer[1], receivedAnswer[2], receivedAnswer[3], receivedAnswer[4], receivedAnswer[5], receivedAnswer[6], receivedAnswer[7], receivedAnswer[8], receivedAnswer[9], diff --git a/common/i2c.c b/common/i2c.c index e4d3a4723..8a8b6693b 100644 --- a/common/i2c.c +++ b/common/i2c.c @@ -342,7 +342,7 @@ bool I2C_WriteCmd(uint8_t device_cmd, uint8_t device_address) { I2C_Stop(); if (bBreak) { - if (MF_DBGLEVEL > 3) DbpString(I2C_ERROR); + if (DBGLEVEL > 3) DbpString(I2C_ERROR); return false; } return true; @@ -372,7 +372,7 @@ bool I2C_WriteByte(uint8_t data, uint8_t device_cmd, uint8_t device_address) { I2C_Stop(); if (bBreak) { - if (MF_DBGLEVEL > 3) DbpString(I2C_ERROR); + if (DBGLEVEL > 3) DbpString(I2C_ERROR); return false; } return true; @@ -410,7 +410,7 @@ bool I2C_BufferWrite(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t dev I2C_Stop(); if (bBreak) { - if (MF_DBGLEVEL > 3) DbpString(I2C_ERROR); + if (DBGLEVEL > 3) DbpString(I2C_ERROR); return false; } return true; @@ -453,7 +453,7 @@ int16_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t d if (bBreak) { I2C_Stop(); - if (MF_DBGLEVEL > 3) DbpString(I2C_ERROR); + if (DBGLEVEL > 3) DbpString(I2C_ERROR); return 0; } @@ -522,7 +522,7 @@ int16_t I2C_ReadFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t if (bBreak) { I2C_Stop(); - if (MF_DBGLEVEL > 3) DbpString(I2C_ERROR); + if (DBGLEVEL > 3) DbpString(I2C_ERROR); return 0; } @@ -586,7 +586,7 @@ bool I2C_WriteFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t d I2C_Stop(); if (bBreak) { - if (MF_DBGLEVEL > 3) DbpString(I2C_ERROR); + if (DBGLEVEL > 3) DbpString(I2C_ERROR); return false; } return true; @@ -684,7 +684,7 @@ bool GetATR(smart_card_atr_t *card_ptr) { chksum ^= card_ptr->atr[i]; if (chksum) { - if (MF_DBGLEVEL > 2) DbpString("Wrong ATR checksum"); + if (DBGLEVEL > 2) DbpString("Wrong ATR checksum"); } } } @@ -740,7 +740,7 @@ void SmartCardRaw(uint64_t arg0, uint64_t arg1, uint8_t *data) { // asBytes = A0 A4 00 00 02 // arg1 = len 5 bool res = I2C_BufferWrite(data, arg1, ((flags & SC_RAW_T0) ? I2C_DEVICE_CMD_SEND_T0 : I2C_DEVICE_CMD_SEND), I2C_DEVICE_ADDRESS_MAIN); - if (!res && MF_DBGLEVEL > 3) DbpString(I2C_ERROR); + if (!res && DBGLEVEL > 3) DbpString(I2C_ERROR); // read bytes from module len = ISO7618_MAX_FRAME; diff --git a/include/common.h b/include/common.h index 682c8da94..ec17c256e 100644 --- a/include/common.h +++ b/include/common.h @@ -23,12 +23,12 @@ extern "C" { typedef unsigned char byte_t; // debug -#define MF_DBG_NONE 0 // no messages -#define MF_DBG_ERROR 1 // errors only -#define MF_DBG_INFO 2 // errors + info messages -#define MF_DBG_DEBUG 3 // errors + info + debug messages -#define MF_DBG_EXTENDED 4 // errors + info + debug + breaking debug messages -extern int MF_DBGLEVEL; +#define DBG_NONE 0 // no messages +#define DBG_ERROR 1 // errors only +#define DBG_INFO 2 // errors + info messages +#define DBG_DEBUG 3 // errors + info + debug messages +#define DBG_EXTENDED 4 // errors + info + debug + breaking debug messages +extern int DBGLEVEL; // Flashmem spi baudrate extern uint32_t FLASHMEM_SPIBAUDRATE;