Skip to content

Commit

Permalink
Linux: Detect soon when pm3 is unplugged
Browse files Browse the repository at this point in the history
  • Loading branch information
doegox committed May 6, 2019
1 parent fa8bd85 commit ec5876b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions client/comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ __attribute__((force_align_arg_pointer))
*uart_communication(void *targ) {
communication_arg_t *connection = (communication_arg_t *)targ;
uint32_t rxlen;
bool sendfailed = false;
bool commfailed = false;
PacketResponseNG rx;
PacketResponseNGRaw rx_raw;

Expand All @@ -336,8 +336,8 @@ __attribute__((force_align_arg_pointer))

// Signal to main thread that communications seems off.
// main thread will kill and restart this thread.
if ( sendfailed ) {
PrintAndLogEx(WARNING, "sending bytes to Proxmark3 device " _RED_("failed"));
if ( commfailed ) {
PrintAndLogEx(WARNING, "Communicating with Proxmark3 device " _RED_("failed"));
__atomic_test_and_set(&comm_thread_dead, __ATOMIC_SEQ_CST);
break;
}
Expand Down Expand Up @@ -458,6 +458,9 @@ __attribute__((force_align_arg_pointer))
PrintAndLogEx(WARNING, "Received packet frame preamble too short: %d/%d", rxlen, sizeof(PacketResponseNGPreamble));
error = true;
}
if (res == PM3_ENOTTY) {
commfailed = true;
}
}

pthread_mutex_unlock(&spMutex);
Expand Down Expand Up @@ -485,14 +488,14 @@ __attribute__((force_align_arg_pointer))
if (txBufferNGLen) { // NG packet
res = uart_send(sp, (uint8_t *) &txBufferNG, txBufferNGLen);
if (res == PM3_EIO) {
sendfailed = true;
commfailed = true;
}
conn.last_command = txBufferNG.pre.cmd;
txBufferNGLen = 0;
} else {
res = uart_send(sp, (uint8_t *) &txBuffer, sizeof(PacketCommandOLD));
if (res == PM3_EIO) {
sendfailed = true;
commfailed = true;
}
conn.last_command = txBuffer.cmd;
}
Expand Down

0 comments on commit ec5876b

Please sign in to comment.