From af9567a19e2c5173f80ee238146b287b8bf64cbd Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 12 Sep 2025 22:00:46 +0200 Subject: [PATCH] style --- armsrc/Standalone/hf_bog.c | 8 ++++---- armsrc/fpgaloader.c | 2 +- armsrc/i2c.c | 14 +++++++------- armsrc/lfops.c | 4 ++-- armsrc/mifaresim.c | 23 ++++++++++++++--------- armsrc/mifaresniff_disabled.c | 2 +- client/src/wiegand_formats.c | 14 +++++++------- 7 files changed, 36 insertions(+), 31 deletions(-) diff --git a/armsrc/Standalone/hf_bog.c b/armsrc/Standalone/hf_bog.c index d5d94fe0f..93819aed8 100644 --- a/armsrc/Standalone/hf_bog.c +++ b/armsrc/Standalone/hf_bog.c @@ -90,7 +90,7 @@ static void RAMFUNC SniffAndStore(uint8_t param) { // Setup and start DMA. if (!FpgaSetupSscDma((uint8_t *)dmaBuf, DMA_BUFFER_SIZE)) { - if (g_dbglevel > 1) { + if (g_dbglevel > DBG_ERROR) { Dbprintf("FpgaSetupSscDma failed. Exiting"); } return; @@ -161,7 +161,7 @@ static void RAMFUNC SniffAndStore(uint8_t param) { if (triggered) { if ((receivedCmd) && ((receivedCmd[0] == MIFARE_ULEV1_AUTH) || (receivedCmd[0] == MIFARE_ULC_AUTH_1))) { - if (g_dbglevel > 1) + if (g_dbglevel > DBG_ERROR) Dbprintf("PWD-AUTH KEY: 0x%02x%02x%02x%02x", receivedCmd[1], receivedCmd[2], receivedCmd[3], receivedCmd[4]); @@ -225,7 +225,7 @@ static void RAMFUNC SniffAndStore(uint8_t param) { // Write stuff to spiffs logfile if (auth_attempts > 0) { - if (g_dbglevel > 1) + if (g_dbglevel > DBG_ERROR) Dbprintf("[!] Authentication attempts = %u", auth_attempts); if (!exists_in_spiffs((char *)HF_BOG_LOGFILE)) { @@ -235,7 +235,7 @@ static void RAMFUNC SniffAndStore(uint8_t param) { } } - if (g_dbglevel > 1) + if (g_dbglevel > DBG_ERROR) Dbprintf("[!] Wrote %u Authentication attempts into logfile", auth_attempts); SpinErr(LED_A, 200, 5); diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c index b3d739a6d..384ec236c 100644 --- a/armsrc/fpgaloader.c +++ b/armsrc/fpgaloader.c @@ -635,7 +635,7 @@ int FpgaGetCurrent(void) { // if HF, Disable SSC DMA // turn off trace and leds off. void switch_off(void) { - if (g_dbglevel > 3) { + if (g_dbglevel > DBG_DEBUG) { Dbprintf("switch_off"); } diff --git a/armsrc/i2c.c b/armsrc/i2c.c index b1af6e30a..89106bb99 100644 --- a/armsrc/i2c.c +++ b/armsrc/i2c.c @@ -401,7 +401,7 @@ bool I2C_WriteCmd(uint8_t device_cmd, uint8_t device_address) { if (_break) { - if (g_dbglevel > 3) DbpString(I2C_ERROR); + if (g_dbglevel > DBG_DEBUG) DbpString(I2C_ERROR); return false; } @@ -436,7 +436,7 @@ bool I2C_WriteByte(uint8_t data, uint8_t device_cmd, uint8_t device_address) { I2C_Stop(); if (_break) { - if (g_dbglevel > 3) DbpString(I2C_ERROR); + if (g_dbglevel > DBG_DEBUG) DbpString(I2C_ERROR); return false; } return true; @@ -479,7 +479,7 @@ bool I2C_BufferWrite(const uint8_t *data, uint16_t len, uint8_t device_cmd, uint I2C_Stop(); if (_break) { - if (g_dbglevel > 3) DbpString(I2C_ERROR); + if (g_dbglevel > DBG_DEBUG) DbpString(I2C_ERROR); return false; } return true; @@ -530,7 +530,7 @@ int16_t I2C_BufferRead(uint8_t *data, uint16_t len, uint8_t device_cmd, uint8_t if (_break) { I2C_Stop(); - if (g_dbglevel > 3) DbpString(I2C_ERROR); + if (g_dbglevel > DBG_DEBUG) DbpString(I2C_ERROR); return 0; } @@ -641,7 +641,7 @@ int16_t I2C_ReadFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t if (_break) { I2C_Stop(); - if (g_dbglevel > 3) DbpString(I2C_ERROR); + if (g_dbglevel > DBG_DEBUG) DbpString(I2C_ERROR); return 0; } @@ -713,7 +713,7 @@ bool I2C_WriteFW(const uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uin I2C_Stop(); if (_break) { - if (g_dbglevel > 3) DbpString(I2C_ERROR); + if (g_dbglevel > DBG_DEBUG) DbpString(I2C_ERROR); return false; } return true; @@ -825,7 +825,7 @@ bool GetATR(smart_card_atr_t *card_ptr, bool verbose) { chksum ^= card_ptr->atr[i]; if (chksum) { - if (g_dbglevel > 2) DbpString("Wrong ATR checksum"); + if (g_dbglevel > DBG_INFO) DbpString("Wrong ATR checksum"); } } } diff --git a/armsrc/lfops.c b/armsrc/lfops.c index ac65c425c..09574ad8c 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -374,7 +374,7 @@ void loadT55xxConfig(void) { memcpy((uint8_t *)&T55xx_Timing, buf, T55XX_CONFIG_LEN); if (size == T55XX_CONFIG_LEN) { - if (g_dbglevel > 1) DbpString("T55XX Config load success"); + if (g_dbglevel > DBG_ERROR) DbpString("T55XX Config load success"); } BigBuf_free(); @@ -1889,7 +1889,7 @@ void T55xxDangerousRawTest(const uint8_t *data, bool ledcontrol) { for (uint8_t i = 0; i < c->bitlen; i++) len = T55xx_SetBits(bs, len, c->data[i], 1, sizeof(bs)); - if (g_dbglevel > 1) { + if (g_dbglevel > DBG_ERROR) { Dbprintf("LEN %i, TIMING %i", len, c->time); for (uint8_t i = 0; i < len; i++) { uint8_t sendbits = (bs[BITSTREAM_BYTE(i)] >> BITSTREAM_BIT(i)); diff --git a/armsrc/mifaresim.c b/armsrc/mifaresim.c index b69ebe0c6..989345493 100644 --- a/armsrc/mifaresim.c +++ b/armsrc/mifaresim.c @@ -513,7 +513,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *uid, uint16_t struct Crypto1State *pcs; pcs = &mpcs; - uint32_t numReads = 0; //Counts numer of times reader reads a block + uint32_t numReads = 0; // Counts numer of times reader reads a block uint8_t receivedCmd[MAX_MIFARE_FRAME_SIZE] = {0x00}; uint8_t receivedCmd_dec[MAX_MIFARE_FRAME_SIZE] = {0x00}; uint8_t receivedCmd_par[MAX_MIFARE_PARITY_SIZE] = {0x00}; @@ -526,10 +526,10 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *uid, uint16_t uint8_t rats_len = 0; - //Here, we collect UID,sector,keytype,NT,AR,NR,NT2,AR2,NR2 + // Here, we collect UID,sector,keytype,NT,AR,NR,NT2,AR2,NR2 // This will be used in the reader-only attack. - //allow collecting up to 16 sets of nonces to allow recovery of up to 16 keys + // allow collecting up to 16 sets of nonces to allow recovery of up to 16 keys #define ATTACK_KEY_COUNT 16 nonces_t ar_nr_resp[ATTACK_KEY_COUNT]; // for moebius attack type memset(ar_nr_resp, 0x00, sizeof(ar_nr_resp)); @@ -580,25 +580,29 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *uid, uint16_t } FpgaEnableTracing(); - //Now, get data + // Now, get data int res = EmGetCmd(receivedCmd, sizeof(receivedCmd), &receivedCmd_len, receivedCmd_par); - if (res == 2) { //Field is off! - //FpgaDisableTracing(); + if (res == 2) { // Field is off! + // FpgaDisableTracing(); if ((flags & FLAG_CVE21_0430) == FLAG_CVE21_0430) { p_em[1] = 0x21; cve_flipper = 0; } LEDsoff(); cardSTATE = MFEMUL_NOFIELD; - if (g_dbglevel >= DBG_EXTENDED) + + if (g_dbglevel >= DBG_EXTENDED) { Dbprintf("cardSTATE = MFEMUL_NOFIELD"); + } continue; + } else if (res == 1) { // button pressed FpgaDisableTracing(); button_pushed = true; - if (g_dbglevel >= DBG_EXTENDED) + if (g_dbglevel >= DBG_EXTENDED) { Dbprintf("Button pressed"); + } break; } @@ -1438,12 +1442,13 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *uid, uint16_t } } } + if (g_dbglevel >= DBG_ERROR) { Dbprintf("Emulator stopped. Tracing: %d trace length: %d ", get_tracing(), BigBuf_get_traceLen()); } if ((flags & FLAG_INTERACTIVE) == FLAG_INTERACTIVE) { // Interactive mode flag, means we need to send ACK - //Send the collected ar_nr in the response + // Send the collected ar_nr in the response reply_ng(CMD_HF_MIFARE_SIMULATE, button_pushed ? PM3_EOPABORTED : PM3_SUCCESS, (uint8_t *)&ar_nr_resp[index], sizeof(nonces_t)); } diff --git a/armsrc/mifaresniff_disabled.c b/armsrc/mifaresniff_disabled.c index 92888a1ea..772dc7e8e 100644 --- a/armsrc/mifaresniff_disabled.c +++ b/armsrc/mifaresniff_disabled.c @@ -84,7 +84,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 (g_dbglevel > 1) Dbprintf("[!] FpgaSetupSscDma failed. Exiting"); + if (g_dbglevel > DBG_ERROR) Dbprintf("[!] FpgaSetupSscDma failed. Exiting"); return; } diff --git a/client/src/wiegand_formats.c b/client/src/wiegand_formats.c index ee00f2dd5..29ee46d93 100644 --- a/client/src/wiegand_formats.c +++ b/client/src/wiegand_formats.c @@ -732,7 +732,7 @@ static bool Pack_S12906b(int format_idx, wiegand_card_t *card, wiegand_message_t packed->Length = 36; // Set number of bits set_linear_field(packed, card->FacilityCode, 1, 8); set_linear_field(packed, card->CardNumber, 11, 24); - set_bit_by_position(packed, oddparity32 (get_nonlinear_field(packed, S12906b_BITS_USED_BY_PARITY, S12906b_odd_parity_bit_0)), 0); + set_bit_by_position(packed, oddparity32(get_nonlinear_field(packed, S12906b_BITS_USED_BY_PARITY, S12906b_odd_parity_bit_0)), 0); set_bit_by_position(packed, evenparity32(get_nonlinear_field(packed, S12906b_BITS_USED_BY_PARITY, S12906b_even_parity_bit_9)), 9); set_bit_by_position(packed, evenparity32(get_nonlinear_field(packed, S12906b_BITS_USED_BY_PARITY, S12906b_even_parity_bit_10)), 10); if (preamble) { @@ -748,7 +748,7 @@ static bool Unpack_S12906b(wiegand_message_t *packed, wiegand_card_t *card) { card->FacilityCode = get_linear_field(packed, 1, 8); card->CardNumber = get_linear_field(packed, 11, 24); if (card->FacilityCode != S12906b_FACILITY_CODE) return false; - bool odd_1 = get_bit_by_position(packed, 0) == oddparity32( get_nonlinear_field(packed, S12906b_BITS_USED_BY_PARITY, S12906b_odd_parity_bit_0)); + bool odd_1 = get_bit_by_position(packed, 0) == oddparity32(get_nonlinear_field(packed, S12906b_BITS_USED_BY_PARITY, S12906b_odd_parity_bit_0)); bool even1 = get_bit_by_position(packed, 9) == evenparity32(get_nonlinear_field(packed, S12906b_BITS_USED_BY_PARITY, S12906b_even_parity_bit_9)); bool even2 = get_bit_by_position(packed, 10) == evenparity32(get_nonlinear_field(packed, S12906b_BITS_USED_BY_PARITY, S12906b_even_parity_bit_10)); card->ParityValid = odd_1 && even1 && even2; @@ -1548,8 +1548,8 @@ static const cardformat_t FormatTable[] = { {"C1k48s", Pack_C1k48s, Unpack_C1k48s, "HID Corporate 1000 48-bit std", 48, {1, 1, 0, 0, 1, 0x003FFFFFu, 0x00000000007FFFFFu, 0x00000000u, 0x00000000u}}, // imported from old pack/unpack {"Avig56", Pack_Avig56, Unpack_Avig56, "Avigilon 56-bit", 56, {1, 1, 0, 0, 1, 0x000FFFFFu, 0x00000003FFFFFFFFu, 0x00000000u, 0x00000000u}}, {"IR56", Pack_IR56, Unpack_IR56, "Inner Range 56-bit", 56, {1, 1, 0, 0, 0, 0x00FFFFFFu, 0x00000000FFFFFFFFu, 0x00000000u, 0x00000000u}}, - {NULL, NULL, NULL, NULL, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0}} // Must null terminate array -}; + {NULL, NULL, NULL, NULL, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0}} // Must null terminate array +}; void HIDListFormats(void) { if (FormatTable[0].Name == NULL) @@ -1610,16 +1610,16 @@ bool validate_card_limit(int format_idx, wiegand_card_t *card) { cardformatdescriptor_t card_descriptor = FormatTable[format_idx].Fields; // If a field is not supported, it's implicitly required to be zero - if ((!card_descriptor.hasCardNumber ) && (card->CardNumber != 0u)) { + if ((!card_descriptor.hasCardNumber) && (card->CardNumber != 0u)) { return false; // Format does not support card number, but non-zero card number provided } if ((!card_descriptor.hasFacilityCode) && (card->FacilityCode != 0u)) { return false; // Format does not support facility code, but non-zero facility code provided } - if ((!card_descriptor.hasIssueLevel ) && (card->IssueLevel != 0u)) { + if ((!card_descriptor.hasIssueLevel) && (card->IssueLevel != 0u)) { return false; // Format does not support issue levels, but non-zero issue level provided } - if ((!card_descriptor.hasOEMCode ) && (card->OEM != 0u)) { + if ((!card_descriptor.hasOEMCode) && (card->OEM != 0u)) { return false; // Format does not support OEM codes, but non-zero OEM code provided } return !((card->FacilityCode > card_descriptor.MaxFC) ||