Skip to content

Commit

Permalink
Merge pull request RfidResearchGroup#2536 from douniwan5788/resp_init
Browse files Browse the repository at this point in the history
refactor: cleanup PacketResponseNG init
  • Loading branch information
iceman1001 authored Sep 24, 2024
2 parents 9129cd6 + ef0bae7 commit 14dcc9d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 57 deletions.
14 changes: 2 additions & 12 deletions client/src/cmdhfmfhard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
13 changes: 2 additions & 11 deletions client/src/cmdlf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions client/src/cmdlfem4x50.c
Original file line number Diff line number Diff line change
Expand Up @@ -1259,18 +1259,9 @@ static int CmdEM4x50Sim(const char *Cmd) {

PrintAndLogEx(INFO, "Press " _GREEN_("pm3 button") " or " _GREEN_("<Enter>") " 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 {
Expand Down
28 changes: 5 additions & 23 deletions client/src/comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;


Expand Down

0 comments on commit 14dcc9d

Please sign in to comment.