From 3df5fb6d400cbcc06f49a65019602b3bf5f6fb80 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 31 Dec 2023 09:43:45 +0100 Subject: [PATCH] cleaned up style --- armsrc/mifarecmd.c | 25 +++++++++++++------------ armsrc/mifareutil.h | 22 ++++++++++++---------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 318401e3d..bd8b660f5 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -2710,14 +2710,14 @@ void MifareHasStaticEncryptedNonce(uint8_t block_no, uint8_t key_type, uint8_t * set_tracing(true); int retval = PM3_SUCCESS; - uint8_t *uid = BigBuf_malloc(10); - memset(uid, 0x00, 10); + uint8_t *uid = BigBuf_calloc(10); + uint64_t ui64key = bytes_to_num(key, 6); uint8_t data[1] = { NONCE_FAIL }; + struct Crypto1State mpcs = {0, 0}; struct Crypto1State *pcs; pcs = &mpcs; - uint64_t ui64key = bytes_to_num(key, 6); iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); @@ -2774,6 +2774,7 @@ void OnSuccessMagic(void) { LEDsoff(); set_tracing(false); } + void OnErrorMagic(uint8_t reason) { // ACK, ISOK, reason,0,0,0 reply_mix(CMD_ACK, 0, reason, 0, 0, 0); @@ -2782,8 +2783,8 @@ void OnErrorMagic(uint8_t reason) { int DoGen3Cmd(uint8_t *cmd, uint8_t cmd_len) { int retval = PM3_SUCCESS; - uint8_t *par = BigBuf_malloc(MAX_PARITY_SIZE); - uint8_t *buf = BigBuf_malloc(PM3_CMD_DATA_SIZE); + uint8_t *par = BigBuf_calloc(MAX_PARITY_SIZE); + uint8_t *buf = BigBuf_calloc(PM3_CMD_DATA_SIZE); LED_B_ON(); uint32_t save_iso14a_timeout = iso14a_get_timeout(); @@ -2806,9 +2807,9 @@ int DoGen3Cmd(uint8_t *cmd, uint8_t cmd_len) { void MifareGen3UID(uint8_t uidlen, uint8_t *uid) { int retval = PM3_SUCCESS; uint8_t uid_cmd[5] = { 0x90, 0xfb, 0xcc, 0xcc, 0x07 }; - uint8_t *old_uid = BigBuf_malloc(10); - uint8_t *cmd = BigBuf_malloc(sizeof(uid_cmd) + uidlen + 2); - iso14a_card_select_t *card_info = (iso14a_card_select_t *) BigBuf_malloc(sizeof(iso14a_card_select_t)); + uint8_t *old_uid = BigBuf_calloc(10); + uint8_t *cmd = BigBuf_calloc(sizeof(uid_cmd) + uidlen + 2); + iso14a_card_select_t *card_info = (iso14a_card_select_t *) BigBuf_calloc(sizeof(iso14a_card_select_t)); iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); clear_trace(); @@ -2838,12 +2839,12 @@ OUT: } void MifareGen3Blk(uint8_t block_len, uint8_t *block) { -#define MIFARE_BLOCK_SIZE (MAX_MIFARE_FRAME_SIZE - 2) + int retval = PM3_SUCCESS; uint8_t block_cmd[5] = { 0x90, 0xf0, 0xcc, 0xcc, 0x10 }; - uint8_t *uid = BigBuf_malloc(10); - uint8_t *cmd = BigBuf_malloc(sizeof(block_cmd) + MAX_MIFARE_FRAME_SIZE); - iso14a_card_select_t *card_info = (iso14a_card_select_t *) BigBuf_malloc(sizeof(iso14a_card_select_t)); + uint8_t *uid = BigBuf_calloc(10); + uint8_t *cmd = BigBuf_calloc(sizeof(block_cmd) + MAX_MIFARE_FRAME_SIZE); + iso14a_card_select_t *card_info = (iso14a_card_select_t *) BigBuf_calloc(sizeof(iso14a_card_select_t)); iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); clear_trace(); diff --git a/armsrc/mifareutil.h b/armsrc/mifareutil.h index e7ee0f7f9..fd0749058 100644 --- a/armsrc/mifareutil.h +++ b/armsrc/mifareutil.h @@ -30,22 +30,24 @@ #define AUTH_FIRST 0 #define AUTH_NESTED 2 -#define AUTHENTICATION_TIMEOUT 848 // card times out 1ms after wrong authentication (according to NXP documentation) +#define AUTHENTICATION_TIMEOUT 848 // card times out 1ms after wrong authentication (according to NXP documentation) #define PRE_AUTHENTICATION_LEADTIME 400 // some (non standard) cards need a pause after select before they are ready for first authentication // reader voltage field detector -#define MF_MINFIELDV 4000 +#define MF_MINFIELDV 4000 // Mifare 4k/2k/1k/mini Max Block / Max Sector -#define MIFARE_4K_MAXBLOCK 256 -#define MIFARE_2K_MAXBLOCK 128 -#define MIFARE_1K_MAXBLOCK 64 -#define MIFARE_MINI_MAXBLOCK 20 +#define MIFARE_4K_MAXBLOCK 256 +#define MIFARE_2K_MAXBLOCK 128 +#define MIFARE_1K_MAXBLOCK 64 +#define MIFARE_MINI_MAXBLOCK 20 -#define MIFARE_MINI_MAXSECTOR 5 -#define MIFARE_1K_MAXSECTOR 16 -#define MIFARE_2K_MAXSECTOR 32 -#define MIFARE_4K_MAXSECTOR 40 +#define MIFARE_MINI_MAXSECTOR 5 +#define MIFARE_1K_MAXSECTOR 16 +#define MIFARE_2K_MAXSECTOR 32 +#define MIFARE_4K_MAXSECTOR 40 + +#define MIFARE_BLOCK_SIZE 16 //mifare emulator states #define MFEMUL_NOFIELD 0