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

@ -423,7 +423,7 @@ int CmdVersion(const char *Cmd) {
#else
PrintAndLogEx(NORMAL, "\n\e[34m [ Proxmark3 RFID instrument ]\e[0m\n");
#endif
char s[50] = {0};
char s[60] = {0};
#if defined(WITH_FLASH) || defined(WITH_SMARTCARD) || defined(WITH_FPC)
strncat(s, "build for RDV40 with ", sizeof(s) - strlen(s) - 1);
#endif
@ -434,7 +434,11 @@ int CmdVersion(const char *Cmd) {
strncat(s, "smartcard; ", sizeof(s) - strlen(s) - 1);
#endif
#ifdef WITH_FPC
#ifdef WITH_FPC_HOST
strncat(s, "fpc-host; ", sizeof(s) - strlen(s) - 1);
#else
strncat(s, "fpc; ", sizeof(s) - strlen(s) - 1);
#endif
#endif
PrintAndLogEx(NORMAL, "\n [ CLIENT ]");
PrintAndLogEx(NORMAL, " client: iceman %s \n", s);

View file

@ -194,7 +194,7 @@ static void UsbCommandReceived(UsbCommand *c) {
/*
bool hookUpPM3() {
bool ret = false;
sp = uart_open( comport );
sp = uart_open( comport, speed );
if (sp == INVALID_SERIAL_PORT) {
PrintAndLogEx(WARNING, "Reconnect failed, retrying... (reason: invalid serial port)\n");
@ -298,17 +298,17 @@ __attribute__((force_align_arg_pointer))
return NULL;
}
bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode) {
bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode, uint32_t speed) {
char *portname = (char *)port;
if (!wait_for_port) {
sp = uart_open(portname);
sp = uart_open(portname, speed);
} else {
PrintAndLogEx(SUCCESS, "Waiting for Proxmark to appear on " _YELLOW_("%s"), portname);
fflush(stdout);
int openCount = 0;
do {
sp = uart_open(portname);
sp = uart_open(portname, speed);
msleep(500);
printf(".");
fflush(stdout);

View file

@ -54,7 +54,8 @@ void *uart_receiver(void *targ);
void SendCommand(UsbCommand *c);
void clearCommandBuffer();
bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode);
#define FLASHMODE_SPEED 460800
bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode, uint32_t speed);
void CloseProxmark(void);
bool WaitForResponseTimeoutW(uint32_t cmd, UsbCommand *response, size_t ms_timeout, bool show_warning);

View file

@ -321,7 +321,7 @@ static int enter_bootloader(char *serial_port_name) {
// Let time to OS to make the port disappear
msleep(1000);
bool opened = OpenProxmark(serial_port_name, true, 60, true);
bool opened = OpenProxmark(serial_port_name, true, 60, true, FLASHMODE_SPEED);
if (opened) {
fprintf(stdout, " " _GREEN_("Found") "\n");
return 0;

View file

@ -81,7 +81,7 @@ int main(int argc, char **argv) {
char *serial_port_name = argv[1];
if (!OpenProxmark(serial_port_name, true, 60, true)) {
if (!OpenProxmark(serial_port_name, true, 60, true, FLASHMODE_SPEED)) {
fprintf(stderr, "Could not find Proxmark on " _RED_("%s") ".\n\n", serial_port_name);
return -1;
} else {

View file

@ -259,6 +259,9 @@ int main(int argc, char *argv[]) {
bool addLuaExec = false;
char *script_cmds_file = NULL;
char *script_cmd = NULL;
char *lastarg = NULL;
char *port = NULL;
uint32_t speed = 0;
/* initialize history */
using_history();
@ -272,7 +275,9 @@ int main(int argc, char *argv[]) {
return 1;
}
for (int i = 1; i < argc; i++) {
uint32_t i = 1;
port = argv[i++];
for (i; i < argc; i++) {
// helptext
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
@ -291,29 +296,58 @@ int main(int argc, char *argv[]) {
if (strcmp(argv[i], "-f") == 0 || strcmp(argv[i], "-flush") == 0) {
SetFlushAfterWrite(true);
PrintAndLogEx(INFO, "Output will be flushed after every print.\n");
continue;
}
// set baudrate
if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "-baud") == 0) {
uint32_t tmpspeed = strtoul(argv[i+1], NULL, 10);
if ((tmpspeed == ULONG_MAX) || (tmpspeed == 0)) {
PrintAndLogEx(WARNING, "ERROR: invalid baudrate: %s %s\n", argv[i], argv[i+1]);
return 1;
}
speed = tmpspeed;
i++;
continue;
}
// wait for comport
if (strcmp(argv[i], "-w") == 0 || strcmp(argv[i], "-wait") == 0) {
waitCOMPort = true;
continue;
}
// execute pm3 command
if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "-command") == 0) {
executeCommand = true;
continue;
}
// execute lua script
if (strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "-lua") == 0) {
executeCommand = true;
addLuaExec = true;
continue;
}
if (i < argc - 1) {
// We got an unknown parameter
PrintAndLogEx(WARNING, "WARNING: ignoring invalid parameter: %s\n", argv[i]);
}
if (i == argc - 1) {
// We got presumably a command or a filename
lastarg = argv[argc - 1];
}
}
if (speed == 0)
speed = 460800;
// If the user passed the filename of the 'script' to execute, get it from last parameter
if (argc > 2 && argv[argc - 1] && argv[argc - 1][0] != '-') {
if (lastarg) {
if (executeCommand) {
script_cmd = argv[argc - 1];
script_cmd = lastarg;
while (script_cmd[strlen(script_cmd) - 1] == ' ')
script_cmd[strlen(script_cmd) - 1] = 0x00;
@ -336,7 +370,7 @@ int main(int argc, char *argv[]) {
PrintAndLogEx(SUCCESS, "execute command from commandline: %s\n", script_cmd);
}
} else {
script_cmds_file = argv[argc - 1];
script_cmds_file = lastarg;
}
}
@ -358,7 +392,7 @@ int main(int argc, char *argv[]) {
set_my_executable_path();
// try to open USB connection to Proxmark
usb_present = OpenProxmark(argv[1], waitCOMPort, 20, false);
usb_present = OpenProxmark(port, waitCOMPort, 20, false, speed);
#ifdef HAVE_GUI