From 04c0384d3e36b83f220fc8ded94f57911e967e5c Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 14 Apr 2019 17:25:17 +0200 Subject: [PATCH] Testing pm3 communication --- armsrc/appmain.c | 4 ++++ client/comms.c | 16 +++++++++++++++- client/comms.h | 1 + client/proxmark3.c | 5 +++-- uart/uart_posix.c | 1 + uart/uart_win32.c | 1 + 6 files changed, 25 insertions(+), 3 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 2c16d8f56..03ce3750b 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1443,7 +1443,11 @@ void UsbPacketReceived(uint8_t *packet, int len) { SendStatus(); break; case CMD_PING: +#ifdef WITH_FPC_HOST + cmd_send(CMD_ACK, reply_via_fpc, 0, 0, 0, 0); +#else cmd_send(CMD_ACK, 0, 0, 0, 0, 0); +#endif break; #ifdef WITH_LCD case CMD_LCD_RESET: diff --git a/client/comms.c b/client/comms.c index a2bf8deed..bd5ff93d8 100644 --- a/client/comms.c +++ b/client/comms.c @@ -334,7 +334,6 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode, conn.block_after_ACK = flash_mode; pthread_create(&USB_communication_thread, NULL, &uart_communication, &conn); //pthread_create(&FPC_communication_thread, NULL, &uart_communication, &conn); - fflush(stdout); // create a mutex to avoid interlacing print commands from our different threads //pthread_mutex_init(&print_lock, NULL); @@ -342,6 +341,21 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode, } } +int TestProxmark(void) { + // check if we can communicate with Pm3 + clearCommandBuffer(); + UsbCommand resp; + UsbCommand c = {CMD_PING, {0, 0, 0}, {{0}}}; + SendCommand(&c); + if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) { + PrintAndLogEx(INFO, "Ping successful, communicating with PM3 over %s.", resp.arg[0] == 1 ? "FPC" : "USB"); + return 1; + } else { + PrintAndLogEx(WARNING, _RED_("Ping failed")); + return 0; + } +} + void CloseProxmark(void) { conn.run = false; diff --git a/client/comms.h b/client/comms.h index 483462ac3..68f790eb1 100644 --- a/client/comms.h +++ b/client/comms.h @@ -56,6 +56,7 @@ void clearCommandBuffer(void); #define FLASHMODE_SPEED 460800 bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode, uint32_t speed); +int TestProxmark(void); void CloseProxmark(void); bool WaitForResponseTimeoutW(uint32_t cmd, UsbCommand *response, size_t ms_timeout, bool show_warning); diff --git a/client/proxmark3.c b/client/proxmark3.c index f0239f81c..5e6ec8c1e 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -311,7 +311,6 @@ int main(int argc, char *argv[]) { return 1; } port = argv[i]; - PrintAndLogEx(INFO, "Using UART port %s.\n", port); continue; } @@ -467,8 +466,10 @@ int main(int argc, char *argv[]) { if (port != NULL) usb_present = OpenProxmark(port, waitCOMPort, 20, false, speed); + if (TestProxmark() == 0) + usb_present = false; if (!usb_present) - PrintAndLogEx(NORMAL, "Running in " _YELLOW_("OFFLINE") "mode. Check \"%s -h\" if it's not what you want.\n", exec_name); + PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") "mode. Check \"%s -h\" if it's not what you want.\n", exec_name); #ifdef HAVE_GUI diff --git a/uart/uart_posix.c b/uart/uart_posix.c index 8ea8aa619..f07882ef5 100644 --- a/uart/uart_posix.c +++ b/uart/uart_posix.c @@ -74,6 +74,7 @@ struct timeval timeout = { }; serial_port uart_open(const char *pcPortName, uint32_t speed) { + printf("[=] Using UART port %s.\n", pcPortName); serial_port_unix *sp = calloc(sizeof(serial_port_unix), sizeof(uint8_t)); if (sp == 0) return INVALID_SERIAL_PORT; diff --git a/uart/uart_win32.c b/uart/uart_win32.c index 2ed5c9bcf..e92b49c15 100644 --- a/uart/uart_win32.c +++ b/uart/uart_win32.c @@ -49,6 +49,7 @@ typedef struct { } serial_port_windows; serial_port uart_open(const char *pcPortName, uint32_t speed) { + printf("[=] Using UART port %s.\n", pcPortName); char acPortName[255]; serial_port_windows *sp = calloc(sizeof(serial_port_windows), sizeof(uint8_t));