From 2def48263c42c244dac3035bbcfb767910f78a26 Mon Sep 17 00:00:00 2001 From: douniwan5788 Date: Tue, 24 Sep 2024 01:42:57 +0800 Subject: [PATCH] refactor: cleanup PacketResponseNG init --- client/src/cmdhfmfhard.c | 14 ++------------ client/src/cmdlf.c | 13 ++----------- client/src/cmdlfem4x50.c | 13 ++----------- client/src/comms.c | 28 +++++----------------------- 4 files changed, 11 insertions(+), 57 deletions(-) diff --git a/client/src/cmdhfmfhard.c b/client/src/cmdhfmfhard.c index 78971eb01c4..71abea21685 100644 --- a/client/src/cmdhfmfhard.c +++ b/client/src/cmdhfmfhard.c @@ -1565,18 +1565,8 @@ static int acquire_nonces(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_ FILE *fnonces = NULL; // init to ZERO - PacketResponseNG resp = { - .cmd = 0, - .length = 0, - .magic = 0, - .status = 0, - .crc = 0, - .ng = false, - }; - resp.oldarg[0] = 0; - resp.oldarg[1] = 0; - resp.oldarg[2] = 0; - memset(resp.data.asBytes, 0, PM3_CMD_DATA_SIZE); + PacketResponseNG resp; + memset(resp, 0, sizeof(resp)); uint8_t write_buf[9]; char progress_text[80]; diff --git a/client/src/cmdlf.c b/client/src/cmdlf.c index 59998bc925d..575d9ea9cc3 100644 --- a/client/src/cmdlf.c +++ b/client/src/cmdlf.c @@ -426,18 +426,9 @@ int CmdLFCommandRead(const char *Cmd) { clearCommandBuffer(); SendCommandNG(CMD_LF_MOD_THEN_ACQ_RAW_ADC, (uint8_t *)&payload, PAYLOAD_HEADER_SIZE + cmd_len + 1); - PacketResponseNG resp; // init to ZERO - resp.cmd = 0, - resp.length = 0, - resp.magic = 0, - resp.status = 0, - resp.crc = 0, - resp.ng = false, - resp.oldarg[0] = 0; - resp.oldarg[1] = 0; - resp.oldarg[2] = 0; - memset(resp.data.asBytes, 0, PM3_CMD_DATA_SIZE); + PacketResponseNG resp; + memset(resp, 0, sizeof(resp)); i = 10; // 20sec wait loop diff --git a/client/src/cmdlfem4x50.c b/client/src/cmdlfem4x50.c index aa128b53a14..48354004ae4 100644 --- a/client/src/cmdlfem4x50.c +++ b/client/src/cmdlfem4x50.c @@ -1259,18 +1259,9 @@ static int CmdEM4x50Sim(const char *Cmd) { PrintAndLogEx(INFO, "Press " _GREEN_("pm3 button") " or " _GREEN_("") " to abort simulation"); - PacketResponseNG resp; // init to ZERO - resp.cmd = 0, - resp.length = 0, - resp.magic = 0, - resp.status = 0, - resp.crc = 0, - resp.ng = false, - resp.oldarg[0] = 0; - resp.oldarg[1] = 0; - resp.oldarg[2] = 0; - memset(resp.data.asBytes, 0, PM3_CMD_DATA_SIZE); + PacketResponseNG resp; + memset(resp, 0, sizeof(resp)); bool keypress; do { diff --git a/client/src/comms.c b/client/src/comms.c index 21e63402c79..0c2a79a1e62 100644 --- a/client/src/comms.c +++ b/client/src/comms.c @@ -1030,18 +1030,9 @@ size_t WaitForRawDataTimeout(uint8_t *buffer, size_t len, size_t ms_timeout, boo */ bool WaitForResponseTimeoutW(uint32_t cmd, PacketResponseNG *response, size_t ms_timeout, bool show_warning) { - PacketResponseNG resp; // init to ZERO - resp.cmd = 0, - resp.length = 0, - resp.magic = 0, - resp.status = 0, - resp.crc = 0, - resp.ng = false, - resp.oldarg[0] = 0; - resp.oldarg[1] = 0; - resp.oldarg[2] = 0; - memset(resp.data.asBytes, 0, PM3_CMD_DATA_SIZE); + PacketResponseNG resp; + memset(resp, 0, sizeof(resp)); if (response == NULL) { response = &resp; @@ -1118,23 +1109,14 @@ bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint3 if (dest == NULL) return false; + // init to ZERO PacketResponseNG resp; + memset(resp, 0, sizeof(resp)); + if (response == NULL) { response = &resp; } - // init to ZERO - resp.cmd = 0, - resp.length = 0, - resp.magic = 0, - resp.status = 0, - resp.crc = 0, - resp.ng = false, - resp.oldarg[0] = 0; - resp.oldarg[1] = 0; - resp.oldarg[2] = 0; - memset(resp.data.asBytes, 0, PM3_CMD_DATA_SIZE); - if (bytes == 0) return true;