Skip to content

Commit

Permalink
Add --ms option in hw status
Browse files Browse the repository at this point in the history
To specify the timeout of connection speed test
  • Loading branch information
wh201906 committed Nov 6, 2023
1 parent c851ac7 commit 85e38dd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
15 changes: 9 additions & 6 deletions armsrc/appmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,19 +369,18 @@ static void print_debug_level(void) {

// measure the Connection Speed by sending SpeedTestBufferSize bytes to client and measuring the elapsed time.
// Note: this mimics GetFromBigbuf(), i.e. we have the overhead of the PacketCommandNG structure included.
static void printConnSpeed(void) {
static void printConnSpeed(uint32_t testTimeout) {
DbpString(_CYAN_("Transfer Speed"));
Dbprintf(" Sending packets to client...");

#define CONN_SPEED_TEST_MIN_TIME 500 // in milliseconds
uint8_t *test_data = BigBuf_get_addr();
uint32_t start_time = GetTickCount();
uint32_t delta_time = 0;
uint32_t bytes_transferred = 0;

LED_B_ON();

while (delta_time < CONN_SPEED_TEST_MIN_TIME) {
while (delta_time < testTimeout) {
reply_ng(CMD_DOWNLOADED_BIGBUF, PM3_SUCCESS, test_data, PM3_CMD_DATA_SIZE);
bytes_transferred += PM3_CMD_DATA_SIZE;
delta_time = GetTickCountDelta(start_time);
Expand All @@ -396,7 +395,7 @@ static void printConnSpeed(void) {
/**
* Prints runtime information about the PM3.
**/
static void SendStatus(void) {
static void SendStatus(int32_t speedTestTimeout) {
BigBuf_print_status();
Fpga_print_status();
#ifdef WITH_FLASH
Expand All @@ -412,7 +411,7 @@ static void SendStatus(void) {
#ifdef WITH_ISO14443a
printHf14aConfig(); // HF 14a config
#endif
printConnSpeed();
printConnSpeed(speedTestTimeout);
DbpString(_CYAN_("Various"));

print_stack_usage();
Expand Down Expand Up @@ -2663,7 +2662,11 @@ static void PacketReceived(PacketCommandNG *packet) {
break;
}
case CMD_STATUS: {
SendStatus();
Dbprintf("Packet Len:%d", packet->length);
if (packet->length == 4)
SendStatus(packet->data.asDwords[0]);
else
SendStatus(CONN_SPEED_TEST_MIN_TIME_DEFAULT);
break;
}
case CMD_TIA: {
Expand Down
3 changes: 3 additions & 0 deletions armsrc/appmain.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ int tearoff_hook(void);
// ADC Vref = 3300mV, (240k-10M):240k voltage divider, 140800 mV
#define MAX_ADC_LF_VOLTAGE 140800

// Default connection speed test timeout, used in hw status
#define CONN_SPEED_TEST_MIN_TIME_DEFAULT 500 // in milliseconds

extern int ToSendMax;
extern uint8_t ToSend[];

Expand Down
16 changes: 13 additions & 3 deletions client/src/cmdhw.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,19 +812,29 @@ static int CmdStatus(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hw status",
"Show runtime status information about the connected Proxmark3",
"hw status"
"hw status\n"
"hw status -t 1000 -> Test connection speed with 1000ms timeout\n"
);

void *argtable[] = {
arg_param_begin,
arg_int0("m", "ms", "<ms>", "speed test timeout in micro seconds"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
int32_t speedTestTimeout = arg_get_int_def(ctx, 1, -1);
CLIParserFree(ctx);

clearCommandBuffer();
PacketResponseNG resp;
SendCommandNG(CMD_STATUS, NULL, 0);
if (WaitForResponseTimeout(CMD_STATUS, &resp, 2000) == false) {
if (speedTestTimeout < 0) {
speedTestTimeout = 0;
SendCommandNG(CMD_STATUS, NULL, 0);
} else {
SendCommandNG(CMD_STATUS, (uint8_t *)&speedTestTimeout, sizeof(speedTestTimeout));
}

if (WaitForResponseTimeout(CMD_STATUS, &resp, 2000 + speedTestTimeout) == false) {
PrintAndLogEx(WARNING, "Status command timeout. Communication speed test timed out");
return PM3_ETIMEOUT;
}
Expand Down

0 comments on commit 85e38dd

Please sign in to comment.