mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2024-09-20 23:36:31 +08:00
add: 'hw connect' - lets you connect to a specified serial port. If already connected, it disconnects current port before.
This commit is contained in:
parent
fba239b3e2
commit
61d250a7f8
|
@ -37,7 +37,7 @@ static int usage_hw_detectreader(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usage_hw_setmux(void) {
|
static int usage_hw_setmux(void) {
|
||||||
PrintAndLogEx(NORMAL, "Set mux mode");
|
PrintAndLogEx(NORMAL, "Set the ADC mux to a specific value");
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(NORMAL, "Usage: hw setmux [h] <lopkd | loraw | hipkd | hiraw>");
|
PrintAndLogEx(NORMAL, "Usage: hw setmux [h] <lopkd | loraw | hipkd | hiraw>");
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
PrintAndLogEx(NORMAL, "Options:");
|
||||||
|
@ -49,6 +49,20 @@ static int usage_hw_setmux(void) {
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int usage_hw_connect(void) {
|
||||||
|
PrintAndLogEx(NORMAL, "Connects to a Proxmark3 device via specified serial port");
|
||||||
|
PrintAndLogEx(NORMAL, "");
|
||||||
|
PrintAndLogEx(NORMAL, "Usage: hw connect [h] <port>");
|
||||||
|
PrintAndLogEx(NORMAL, "Options:");
|
||||||
|
PrintAndLogEx(NORMAL, " h This help");
|
||||||
|
PrintAndLogEx(NORMAL, " <port> serial port to connect to");
|
||||||
|
PrintAndLogEx(NORMAL, "");
|
||||||
|
PrintAndLogEx(NORMAL, "Examples:");
|
||||||
|
PrintAndLogEx(NORMAL, " hw connect /dev/ttyACM0 -- *nix ");
|
||||||
|
PrintAndLogEx(NORMAL, " hw connect com3 -- windows");
|
||||||
|
return PM3_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static void lookupChipID(uint32_t iChipID, uint32_t mem_used) {
|
static void lookupChipID(uint32_t iChipID, uint32_t mem_used) {
|
||||||
char asBuff[120];
|
char asBuff[120];
|
||||||
memset(asBuff, 0, sizeof(asBuff));
|
memset(asBuff, 0, sizeof(asBuff));
|
||||||
|
@ -426,7 +440,7 @@ static int CmdSetMux(const char *Cmd) {
|
||||||
else {
|
else {
|
||||||
usage_hw_setmux();
|
usage_hw_setmux();
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommandOLD(CMD_SET_ADC_MUX, arg, 0, 0, NULL, 0);
|
SendCommandOLD(CMD_SET_ADC_MUX, arg, 0, 0, NULL, 0);
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
|
@ -458,9 +472,9 @@ static int CmdPing(const char *Cmd) {
|
||||||
PacketResponseNG resp;
|
PacketResponseNG resp;
|
||||||
SendCommandMIX(CMD_PING, 0, 0, 0, NULL, 0);
|
SendCommandMIX(CMD_PING, 0, 0, 0, NULL, 0);
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1000))
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1000))
|
||||||
PrintAndLogEx(NORMAL, "Ping " _GREEN_("successful"));
|
PrintAndLogEx(SUCCESS, "Ping " _GREEN_("successful"));
|
||||||
else
|
else
|
||||||
PrintAndLogEx(NORMAL, "Ping " _RED_("failed"));
|
PrintAndLogEx(WARNING, "Ping " _RED_("failed"));
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,21 +499,52 @@ static int CmdPingNG(const char *Cmd) {
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int CmdConnect(const char *Cmd) {
|
||||||
|
|
||||||
|
if (tolower(Cmd[0] == 'h'))
|
||||||
|
return usage_hw_connect();
|
||||||
|
|
||||||
|
char *port = NULL;
|
||||||
|
port = (char *)Cmd;
|
||||||
|
|
||||||
|
if (port != NULL) {
|
||||||
|
|
||||||
|
// if we were already connected, disconnect first.
|
||||||
|
if (session.pm3_present) {
|
||||||
|
PrintAndLogEx(INFO, "Disconnecting from current serial port");
|
||||||
|
CloseProxmark();
|
||||||
|
session.pm3_present = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to open serial port
|
||||||
|
session.pm3_present = OpenProxmark(port, false, 20, false, USART_BAUD_RATE);
|
||||||
|
|
||||||
|
if (session.pm3_present && (TestProxmark() != PM3_SUCCESS)) {
|
||||||
|
PrintAndLogEx(ERR, _RED_("ERROR:") "cannot communicate with the Proxmark\n");
|
||||||
|
CloseProxmark();
|
||||||
|
session.pm3_present = false;
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PM3_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static command_t CommandTable[] = {
|
static command_t CommandTable[] = {
|
||||||
{"help", CmdHelp, AlwaysAvailable, "This help"},
|
{"help", CmdHelp, AlwaysAvailable, "This help"},
|
||||||
|
{"connect", CmdConnect, AlwaysAvailable, "connect Proxmark3 to serial port"},
|
||||||
{"detectreader", CmdDetectReader, IfPm3Present, "['l'|'h'] -- Detect external reader field (option 'l' or 'h' to limit to LF or HF)"},
|
{"detectreader", CmdDetectReader, IfPm3Present, "['l'|'h'] -- Detect external reader field (option 'l' or 'h' to limit to LF or HF)"},
|
||||||
{"fpgaoff", CmdFPGAOff, IfPm3Present, "Set FPGA off"},
|
{"fpgaoff", CmdFPGAOff, IfPm3Present, "Set FPGA off"},
|
||||||
{"lcd", CmdLCD, IfPm3Lcd, "<HEX command> <count> -- Send command/data to LCD"},
|
{"lcd", CmdLCD, IfPm3Lcd, "<HEX command> <count> -- Send command/data to LCD"},
|
||||||
{"lcdreset", CmdLCDReset, IfPm3Lcd, "Hardware reset LCD"},
|
{"lcdreset", CmdLCDReset, IfPm3Lcd, "Hardware reset LCD"},
|
||||||
|
{"ping", CmdPing, IfPm3Present, "Test if the Proxmark3 is responding"},
|
||||||
|
{"pingng", CmdPingNG, IfPm3Present, "Test if the Proxmark3 is responsive, using new frame format (experimental)"},
|
||||||
{"readmem", CmdReadmem, IfPm3Present, "[address] -- Read memory at decimal address from flash"},
|
{"readmem", CmdReadmem, IfPm3Present, "[address] -- Read memory at decimal address from flash"},
|
||||||
{"reset", CmdReset, IfPm3Present, "Reset the Proxmark3"},
|
{"reset", CmdReset, IfPm3Present, "Reset the Proxmark3"},
|
||||||
{"setlfdivisor", CmdSetDivisor, IfPm3Present, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
|
{"setlfdivisor", CmdSetDivisor, IfPm3Present, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
|
||||||
{"setmux", CmdSetMux, IfPm3Present, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
|
{"setmux", CmdSetMux, IfPm3Present, "Set the ADC mux to a specific value"},
|
||||||
|
{"status", CmdStatus, IfPm3Present, "Show runtime status information about the connected Proxmark3"},
|
||||||
{"tune", CmdTune, IfPm3Present, "Measure antenna tuning"},
|
{"tune", CmdTune, IfPm3Present, "Measure antenna tuning"},
|
||||||
{"version", CmdVersion, IfPm3Present, "Show version information about the connected Proxmark3"},
|
{"version", CmdVersion, IfPm3Present, "Show version information about the connected Proxmark3"},
|
||||||
{"status", CmdStatus, IfPm3Present, "Show runtime status information about the connected Proxmark3"},
|
|
||||||
{"ping", CmdPing, IfPm3Present, "Test if the Proxmark3 is responding"},
|
|
||||||
{"pingng", CmdPingNG, IfPm3Present, "Test if the Proxmark3 is responsive, using new frame format (experimental)"},
|
|
||||||
{NULL, NULL, NULL, NULL}
|
{NULL, NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -158,8 +158,12 @@ main_loop(char *script_cmds_file, char *script_cmd) {
|
||||||
printprompt = true;
|
printprompt = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
rl_event_hook = check_comm;
|
//rl_event_hook = check_comm;
|
||||||
cmd = readline(PROXPROMPT);
|
if (session.pm3_present )
|
||||||
|
cmd = readline(PROXPROMPT);
|
||||||
|
else
|
||||||
|
cmd = readline("[offline] "PROXPROMPT);
|
||||||
|
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,16 +181,13 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
|
||||||
int uart_send(const serial_port sp, const uint8_t *p_tx, const uint32_t len) {
|
int uart_send(const serial_port sp, const uint8_t *p_tx, const uint32_t len) {
|
||||||
DWORD txlen = 0;
|
DWORD txlen = 0;
|
||||||
int res = WriteFile(((serial_port_windows *)sp)->hPort, p_tx, len, &txlen, NULL);
|
int res = WriteFile(((serial_port_windows *)sp)->hPort, p_tx, len, &txlen, NULL);
|
||||||
int errorcode = GetLastError();
|
if ( res )
|
||||||
if ( res == 0 ) {
|
return PM3_SUCCESS;
|
||||||
printf("[!]res %d | send errorcode == %d \n",res, errorcode);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
int errorcode = GetLastError();
|
||||||
if (res == 0 && errorcode == 2) {
|
if (res == 0 && errorcode == 2) {
|
||||||
return PM3_EIO;
|
return PM3_EIO;
|
||||||
}
|
}
|
||||||
if ( res )
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
|
|
||||||
printf("[!!]res %d | send errorcode == %d \n",res, errorcode);
|
printf("[!!]res %d | send errorcode == %d \n",res, errorcode);
|
||||||
return PM3_ENOTTY;
|
return PM3_ENOTTY;
|
||||||
|
|
Loading…
Reference in a new issue