FPC: got RX working, got client over usart somehow working..., see detailed commit msg

* using WITH_FPC:
  * activate basic usart
  * no double buffer for now, no interrupt
  * usart_dataavailable/usart_readbuffer/usart_writebuffer, to demo it:
    * pm3 client over USB, minicom over usart
    * analyse a d 414243
* using WITH_FPC_HOST:
  * it implies WITH_FPC as it's based on it
  * control pm3 with client over usart
  * EXPERIMENTAL! still some frame desync issues
  * you can connect both from usart & USB with two pm3 clients
    * actually you *have* to connect USB for the moment because
      it's used to send debug messages about buggy usart... See Dbprintf_usb below
  * "sessions": msgs are directed to the latest client to have sent a cmd
  * Dbprintf_usb macro to send msgs to USB client to help debugging usart...
  * We now have an option to run client at different speed as usart is 115200:
    client/proxmark3 /dev/ttyUSB0 -b 115200
  * Consequently, argc,argv handling is a bit revamped, it was so messy...
  * USB and flashing are still at 460800, don't try flashing over usart yet ^^
This commit is contained in:
Philippe Teuwen 2019-04-02 22:06:10 +02:00
commit 21be6d4400
15 changed files with 174 additions and 84 deletions

View file

@ -71,7 +71,7 @@ typedef void *serial_port;
*
* On errors, this method returns INVALID_SERIAL_PORT or CLAIMED_SERIAL_PORT.
*/
serial_port uart_open(const char *pcPortName);
serial_port uart_open(const char *pcPortName, uint32_t speed);
/* Closes the given port.
*/

View file

@ -73,7 +73,7 @@ struct timeval timeout = {
.tv_usec = 30000 // 30 000 micro seconds
};
serial_port uart_open(const char *pcPortName) {
serial_port uart_open(const char *pcPortName, uint32_t speed) {
serial_port_unix *sp = calloc(sizeof(serial_port_unix), sizeof(uint8_t));
if (sp == 0) return INVALID_SERIAL_PORT;
@ -194,14 +194,19 @@ serial_port uart_open(const char *pcPortName) {
// Flush all lingering data that may exist
tcflush(sp->fd, TCIOFLUSH);
// set speed, works for UBUNTU 14.04
bool success = uart_set_speed(sp, 460800);
if (success) {
printf("[=] UART Setting serial baudrate 460800\n");
} else {
uart_set_speed(sp, 115200);
printf("[=] UART Setting serial baudrate 115200\n");
if (!uart_set_speed(sp, speed)) {
// trying some fallbacks automatically
speed = 115200;
if (!uart_set_speed(sp, speed)) {
speed = 9600;
if (!uart_set_speed(sp, speed)) {
uart_close(sp);
printf("[!] UART error while setting baudrate\n");
return INVALID_SERIAL_PORT;
}
}
}
printf("[=] UART Setting serial baudrate %i\n", speed);
return sp;
}

View file

@ -48,7 +48,7 @@ typedef struct {
COMMTIMEOUTS ct; // Serial port time-out configuration
} serial_port_windows;
serial_port uart_open(const char *pcPortName) {
serial_port uart_open(const char *pcPortName, uint32_t speed) {
char acPortName[255];
serial_port_windows *sp = calloc(sizeof(serial_port_windows), sizeof(uint8_t));
@ -87,6 +87,7 @@ serial_port uart_open(const char *pcPortName) {
// all zero's configure: no timeout for read/write used.
// took settings from libnfc/buses/uart.c
#ifdef WITH_FPC
// Still relevant?
sp->ct.ReadIntervalTimeout = 1000;
sp->ct.ReadTotalTimeoutMultiplier = 0;
sp->ct.ReadTotalTimeoutConstant = 1500;
@ -108,22 +109,19 @@ serial_port uart_open(const char *pcPortName) {
PurgeComm(sp->hPort, PURGE_RXABORT | PURGE_RXCLEAR);
#ifdef WITH_FPC
if (uart_set_speed(sp, 115200)) {
printf("[=] UART Setting serial baudrate 115200 [FPC enabled]\n");
} else {
uart_set_speed(sp, 9600);
printf("[=] UART Setting serial baudrate 9600 [FPC enabled]\n");
if (!uart_set_speed(sp, speed)) {
// trying some fallbacks automatically
speed = 115200;
if (!uart_set_speed(sp, speed)) {
speed = 9600;
if (!uart_set_speed(sp, speed)) {
uart_close(sp);
printf("[!] UART error while setting baudrate\n");
return INVALID_SERIAL_PORT;
}
}
}
#else
bool success = uart_set_speed(sp, 460800);
if (success) {
printf("[=] UART Setting serial baudrate 460800\n");
} else {
uart_set_speed(sp, 115200);
printf("[=] UART Setting serial baudrate 115200\n");
}
#endif
printf("[=] UART Setting serial baudrate %i\n", speed);
return sp;
}