Skip to content

Commit

Permalink
rework ping
Browse files Browse the repository at this point in the history
  • Loading branch information
doegox committed May 7, 2019
1 parent bf0ab55 commit 2f1061f
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 36 deletions.
6 changes: 1 addition & 5 deletions armsrc/appmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1521,11 +1521,7 @@ static void PacketReceived(PacketCommandNG *packet) {
case CMD_CAPABILITIES:
SendCapabilities();
case CMD_PING:
if (packet->ng) {
reply_ng(CMD_PING, PM3_SUCCESS, packet->data.asBytes, packet->length);
} else {
reply_mix(CMD_ACK, reply_via_fpc, 0, 0, 0, 0);
}
reply_ng(CMD_PING, PM3_SUCCESS, packet->data.asBytes, packet->length);
break;
#ifdef WITH_LCD
case CMD_LCD_RESET:
Expand Down
4 changes: 2 additions & 2 deletions client/cmdhficlass.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ static int CmdHFiClassELoad(const char *Cmd) {
// Disable fast mode and send a dummy command to make it effective
conn.block_after_ACK = false;
SendCommandNG(CMD_PING, NULL, 0);
WaitForResponseTimeout(CMD_ACK, NULL, 1000);
WaitForResponseTimeout(CMD_PING, NULL, 1000);

PrintAndLogEx(SUCCESS, "sent %d bytes of data to device emulator memory", bytes_sent);
return 0;
Expand Down Expand Up @@ -2038,7 +2038,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) {
// Disable fast mode and send a dummy command to make it effective
conn.block_after_ACK = false;
SendCommandNG(CMD_PING, NULL, 0);
WaitForResponseTimeout(CMD_ACK, NULL, 1000);
WaitForResponseTimeout(CMD_PING, NULL, 1000);

DropField();
free(pre);
Expand Down
2 changes: 1 addition & 1 deletion client/cmdhfmf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,7 @@ static int CmdHF14AMfChk(const char *Cmd) {
// Disable fast mode and send a dummy command to make it effective
conn.block_after_ACK = false;
SendCommandNG(CMD_PING, NULL, 0);
WaitForResponseTimeout(CMD_ACK, NULL, 1000);
WaitForResponseTimeout(CMD_PING, NULL, 1000);


if (createDumpFile) {
Expand Down
30 changes: 12 additions & 18 deletions client/cmdhw.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,22 +465,14 @@ static int CmdStatus(const char *Cmd) {
}

static int CmdPing(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
clearCommandBuffer();
PacketResponseNG resp;
SendCommandNG(CMD_PING, NULL, 0);
if (WaitForResponseTimeout(CMD_ACK, &resp, 1000))
PrintAndLogEx(SUCCESS, "Ping " _GREEN_("successful"));
else
PrintAndLogEx(WARNING, "Ping " _RED_("failed"));
return PM3_SUCCESS;
}

static int CmdPingNG(const char *Cmd) {
uint32_t len = strtol(Cmd, NULL, 0);
if (len > PM3_CMD_DATA_SIZE)
len = PM3_CMD_DATA_SIZE;
PrintAndLogEx(INFO, "PingNG sent with payload len=%d", len);
if (len) {
PrintAndLogEx(INFO, "Ping sent with payload len=%d", len);
} else {
PrintAndLogEx(INFO, "Ping sent");
}
clearCommandBuffer();
PacketResponseNG resp;
uint8_t data[PM3_CMD_DATA_SIZE] = {0};
Expand All @@ -489,11 +481,14 @@ static int CmdPingNG(const char *Cmd) {
SendCommandNG(CMD_PING, data, len);
if (WaitForResponseTimeout(CMD_PING, &resp, 1000)) {
bool error = false;
if (len)
if (len) {
error = memcmp(data, resp.data.asBytes, len) != 0;
PrintAndLogEx((error)? ERR:SUCCESS, "PingNG response received, content is %s", error ? _RED_("NOT ok") : _GREEN_("ok"));
PrintAndLogEx((error)? ERR:SUCCESS, "Ping response " _GREEN_("received") "and content is %s", error ? _RED_("NOT ok") : _GREEN_("ok"));
} else {
PrintAndLogEx((error)? ERR:SUCCESS, "Ping response " _GREEN_("received"));
}
} else
PrintAndLogEx(WARNING, "PingNG response " _RED_("timeout"));
PrintAndLogEx(WARNING, "Ping response " _RED_("timeout"));
return PM3_SUCCESS;
}

Expand Down Expand Up @@ -538,8 +533,7 @@ static command_t CommandTable[] = {
{"fpgaoff", CmdFPGAOff, IfPm3Present, "Set FPGA off"},
{"lcd", CmdLCD, IfPm3Lcd, "<HEX command> <count> -- Send command/data to LCD"},
{"lcdreset", CmdLCDReset, IfPm3Lcd, "Hardware reset LCD"},
{"ping", CmdPing, IfPm3Present, "Test if the Proxmark3 is responding"},
{"pingng", CmdPingNG, IfPm3Present, "Test if the Proxmark3 is responsive, using new frame format (experimental)"},
{"ping", CmdPing, IfPm3Present, "Test if the Proxmark3 is responsive"},
{"readmem", CmdReadmem, IfPm3Present, "[address] -- Read memory at decimal address from flash"},
{"reset", CmdReset, IfPm3Present, "Reset the Proxmark3"},
{"setlfdivisor", CmdSetDivisor, IfPm3Present, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
Expand Down
8 changes: 4 additions & 4 deletions client/cmdlfawid.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ static int usage_lf_awid_brute(void) {
}

static bool sendPing(void) {
SendCommandMIX(CMD_PING, 1, 2, 3, NULL, 0);
SendCommandMIX(CMD_PING, 1, 2, 3, NULL, 0);
SendCommandMIX(CMD_PING, 1, 2, 3, NULL, 0);
SendCommandNG(CMD_PING, NULL, 0);
SendCommandNG(CMD_PING, NULL, 0);
SendCommandNG(CMD_PING, NULL, 0);
clearCommandBuffer();
PacketResponseNG resp;
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000))
if (!WaitForResponseTimeout(CMD_PING, &resp, 1000))
return false;
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions client/cmdlfhid.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ static int usage_lf_hid_brute(void) {

// sending three times. Didn't seem to break the previous sim?
static bool sendPing(void) {
SendCommandMIX(CMD_PING, 1, 2, 3, NULL, 0);
SendCommandMIX(CMD_PING, 1, 2, 3, NULL, 0);
SendCommandMIX(CMD_PING, 1, 2, 3, NULL, 0);
SendCommandNG(CMD_PING, NULL, 0);
SendCommandNG(CMD_PING, NULL, 0);
SendCommandNG(CMD_PING, NULL, 0);
clearCommandBuffer();
PacketResponseNG resp;
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000))
if (!WaitForResponseTimeout(CMD_PING, &resp, 1000))
return false;
return true;
}
Expand Down
1 change: 0 additions & 1 deletion client/comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,6 @@ int TestProxmark(void) {
return PM3_EIO;

SendCommandNG(CMD_CAPABILITIES, NULL, 0);

if (WaitForResponseTimeoutW(CMD_PING, &resp, 1000, false)) {
memcpy(&pm3_capabilities, resp.data.asBytes, resp.length);
conn.send_via_fpc_usart = pm3_capabilities.via_fpc;
Expand Down
2 changes: 1 addition & 1 deletion client/scripting.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static int l_fast_push_mode(lua_State *L) {
// Disable fast mode and send a dummy command to make it effective
if (enable == false) {
SendCommandNG(CMD_PING, NULL, 0);
WaitForResponseTimeout(CMD_ACK, NULL, 1000);
WaitForResponseTimeout(CMD_PING, NULL, 1000);
}

//Push the retval on the stack
Expand Down

0 comments on commit 2f1061f

Please sign in to comment.