mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-22 06:13:27 -07:00
Merge 6e0b2d0beb
into b24930c764
This commit is contained in:
commit
949bfc8738
3 changed files with 60 additions and 16 deletions
|
@ -405,11 +405,17 @@ int CmdTune(const char *Cmd)
|
|||
|
||||
int CmdVersion(const char *Cmd)
|
||||
{
|
||||
|
||||
clearCommandBuffer();
|
||||
UsbCommand c = {CMD_VERSION};
|
||||
static UsbCommand resp = {0, {0, 0, 0}};
|
||||
|
||||
if(*Cmd == 'n') {
|
||||
PrintAndLog("Version Cache Cleared");
|
||||
PrintAndLog("");
|
||||
memset( &resp, 0, sizeof(resp) );
|
||||
}
|
||||
|
||||
clearCommandBuffer();
|
||||
|
||||
if (resp.arg[0] == 0 && resp.arg[1] == 0) { // no cached information available
|
||||
SendCommand(&c);
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
|
||||
|
@ -468,7 +474,7 @@ static command_t CommandTable[] =
|
|||
{"setlfdivisor", CmdSetDivisor, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
|
||||
{"setmux", CmdSetMux, 0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
|
||||
{"tune", CmdTune, 0, "['l'|'h'] -- Measure antenna tuning (option 'l' or 'h' to limit to LF or HF)"},
|
||||
{"version", CmdVersion, 0, "Show version information about the connected Proxmark"},
|
||||
{"version", CmdVersion, 0, "['n'] -- Show version information about the connected Proxmark (option 'nocache' to force getting version from hardware)"},
|
||||
{"status", CmdStatus, 0, "Show runtime status information about the connected Proxmark"},
|
||||
{"ping", CmdPing, 0, "Test if the pm3 is responsive"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
pthread_mutex_t print_lock;
|
||||
|
||||
static serial_port sp;
|
||||
static char* sp_name;
|
||||
static UsbCommand txcmd;
|
||||
volatile static bool txcmd_pending = false;
|
||||
|
||||
|
@ -77,16 +78,52 @@ __attribute__((force_align_arg_pointer))
|
|||
*uart_receiver(void *targ) {
|
||||
struct receiver_arg *arg = (struct receiver_arg*)targ;
|
||||
size_t rxlen;
|
||||
bool need_reconnect = false;
|
||||
|
||||
while (arg->run) {
|
||||
rxlen = 0;
|
||||
if (uart_receive(sp, prx, sizeof(UsbCommand) - (prx-rx), &rxlen) && rxlen) {
|
||||
prx += rxlen;
|
||||
if (prx-rx < sizeof(UsbCommand)) {
|
||||
if( need_reconnect ) {
|
||||
sp = uart_open(sp_name);
|
||||
|
||||
if( sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT )
|
||||
{
|
||||
//PrintAndLog("Reconnect failed, retrying...");
|
||||
|
||||
if( txcmd_pending ) {
|
||||
PrintAndLog("Cannot send bytes to offline proxmark");
|
||||
txcmd_pending = false;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
UsbCommandReceived((UsbCommand*)rx);
|
||||
|
||||
PrintAndLog("Proxmark reconnected!");
|
||||
need_reconnect = false;
|
||||
offline = 0;
|
||||
clearCommandBuffer();
|
||||
}
|
||||
|
||||
rxlen = 0;
|
||||
if (uart_receive(sp, prx, sizeof(UsbCommand) - (prx-rx), &rxlen) ) {
|
||||
if( rxlen ) {
|
||||
prx += rxlen;
|
||||
if (prx-rx < sizeof(UsbCommand)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
UsbCommandReceived((UsbCommand*)rx);
|
||||
}
|
||||
}
|
||||
else {
|
||||
PrintAndLog("Receiving data from proxmark failed, attempting a reconnect");
|
||||
uart_close(sp);
|
||||
sp = INVALID_SERIAL_PORT;
|
||||
offline = 1;
|
||||
txcmd_pending = false;
|
||||
need_reconnect = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
prx = rx;
|
||||
|
||||
if(txcmd_pending) {
|
||||
|
@ -119,7 +156,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool usb_present) {
|
|||
rarg.run = 1;
|
||||
pthread_create(&reader_thread, NULL, &uart_receiver, &rarg);
|
||||
// cache Version information now:
|
||||
CmdVersion(NULL);
|
||||
CmdVersion("nocache");
|
||||
}
|
||||
|
||||
// file with script
|
||||
|
@ -364,6 +401,7 @@ int main(int argc, char* argv[]) {
|
|||
set_my_executable_path();
|
||||
|
||||
// open uart
|
||||
sp_name = argv[1];
|
||||
if (!waitCOMPort) {
|
||||
sp = uart_open(argv[1]);
|
||||
} else {
|
||||
|
@ -418,7 +456,7 @@ int main(int argc, char* argv[]) {
|
|||
#endif
|
||||
|
||||
// Clean up the port
|
||||
if (usb_present) {
|
||||
if (sp != INVALID_SERIAL_PORT && sp != CLAIMED_SERIAL_PORT) {
|
||||
uart_close(sp);
|
||||
}
|
||||
|
||||
|
|
|
@ -158,7 +158,7 @@ bool uart_receive(const serial_port sp, byte_t* pbtRx, size_t pszMaxRxLen, size_
|
|||
if (res == 0) {
|
||||
if (*pszRxLen == 0) {
|
||||
// Error, we received no data
|
||||
return false;
|
||||
return true;
|
||||
} else {
|
||||
// We received some data, but nothing more is available
|
||||
return true;
|
||||
|
@ -178,7 +178,7 @@ bool uart_receive(const serial_port sp, byte_t* pbtRx, size_t pszMaxRxLen, size_
|
|||
res = read(((serial_port_unix*)sp)->fd, pbtRx+(*pszRxLen), byteCount);
|
||||
|
||||
// Stop if the OS has some troubles reading the data
|
||||
if (res <= 0) return false;
|
||||
if (res < 0) return false;
|
||||
|
||||
*pszRxLen += res;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue