Add usart dev cmds & dynamic flash support capability

This commit is contained in:
Philippe Teuwen
2019-05-03 22:30:17 +02:00
parent 8e2d5370f9
commit 3176684f4a
18 changed files with 185 additions and 205 deletions

View File

@@ -10,12 +10,16 @@ ifeq ($(PLTNAME),)
ifeq ($(PLATFORM),)
PLATFORM=PM3RDV4
else
${info using saved PLATFORM '$(PLATFORM)'}
${info using saved PLATFORM: '$(PLATFORM)'}
endif
ifneq ($(PLATFORM_EXTRAS),)
${info using saved PLATFORM_EXTRAS: '$(PLATFORM_EXTRAS)'}
endif
include ../common/Makefile.hal
$(info ===================================================================)
$(info PLATFORM: $(PLATFORM))
$(info Platform name: $(PLTNAME))
$(info PLATFORM: $(PLATFORM))
$(info PLATFORM_EXTRAS: $(PLATFORM_EXTRAS))
$(info Included options: $(PLATFORM_DEFS_INFO))
$(info Standalone mode: $(PLATFORM_DEFS_INFO_STANDALONE))
$(info ===================================================================)
@@ -222,6 +226,7 @@ CMDSRCS = crapto1/crapto1.c \
cmdtrace.c \
cmdflashmem.c \
cmdsmartcard.c \
cmdusart.c \
cmdparser.c \
cmdmain.c \
pm3_binlib.c \

View File

@@ -485,47 +485,7 @@ static char *pb(uint32_t b) {
static int CmdAnalyseA(const char *Cmd) {
int hexlen = 0;
uint8_t cmdp = 0;
bool errors = false;
uint8_t data[PM3_CMD_DATA_SIZE] = {0x00};
if (!IfPm3Fpc()) {
PrintAndLogEx(ERR, "Device has no FPC USART support");
return PM3_EDEVNOTSUPP;
}
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch (tolower(param_getchar(Cmd, cmdp))) {
case 'd':
param_gethex_ex(Cmd, cmdp + 1, data, &hexlen);
hexlen >>= 1;
if (hexlen != sizeof(data)) {
PrintAndLogEx(WARNING, "Read %d bytes of %u", hexlen, sizeof(data));
}
cmdp += 2;
break;
case 'h':
return usage_analyse_a();
default:
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
errors = true;
break;
}
}
//Validations
if (errors || cmdp == 0) return usage_analyse_a();
clearCommandBuffer();
SendCommandOLD(CMD_FPC_SEND, 0, 0, 0, data, PM3_CMD_DATA_SIZE);
PacketResponseNG resp;
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
return 1;
}
PrintAndLogEx(NORMAL, "got ack. Status %d", resp.oldarg[0]);
return 0;
return usage_analyse_a();
/*
PrintAndLogEx(NORMAL, "-- " _BLUE_("its my message") "\n");
PrintAndLogEx(NORMAL, "-- " _RED_("its my message") "\n");

View File

@@ -498,11 +498,14 @@ void pm3_version(bool verbose) {
PrintAndLogEx(NORMAL, "\n" _BLUE_(" [ Proxmark3 RFID instrument ]") "\n");
PrintAndLogEx(NORMAL, "\n [ CLIENT ]");
PrintAndLogEx(NORMAL, " client: RRG/Iceman"); // TODO version info?
PrintAndLogEx(NORMAL, "\n [ PROXMARK ]");
PrintAndLogEx(NORMAL, " external flash: %s", IfPm3Flash() ? _GREEN_("present") : _YELLOW_("absent"));
PrintAndLogEx(NORMAL, " smartcard reader: %s", IfPm3Smartcard() ? _GREEN_("present") : _YELLOW_("absent"));
PrintAndLogEx(NORMAL, " USART for addon support: %s\n", IfPm3FpcHost() ? _GREEN_("present") : _YELLOW_("absent"));
PrintAndLogEx(NORMAL, "\n [ PROXMARK RDV4 ]");
PrintAndLogEx(NORMAL, " external flash: %s", IfPm3Flash() ? _GREEN_("present") : _YELLOW_("absent"));
PrintAndLogEx(NORMAL, " smartcard reader: %s", IfPm3Smartcard() ? _GREEN_("present") : _YELLOW_("absent"));
PrintAndLogEx(NORMAL, "\n [ PROXMARK RDV4 Extras ]");
PrintAndLogEx(NORMAL, " FPC USART for BT add-on support: %s", IfPm3FpcUsartHost() ? _GREEN_("present") : _YELLOW_("absent"));
if (IfPm3FpcUsartDevFromUsb())
PrintAndLogEx(NORMAL, " FPC USART for developer support: %s", _GREEN_("present"));
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, (char *)resp.data.asBytes);
lookupChipID(resp.oldarg[0], resp.oldarg[1]);
}

View File

@@ -42,21 +42,22 @@ static int CmdRev(const char *Cmd) {
}
static command_t CommandTable[] = {
{"help", CmdHelp, AlwaysAvailable, "This help. Use '<command> help' for details of a particular command."},
{"analyse", CmdAnalyse, AlwaysAvailable, "{ Analyse utils... }"},
{"data", CmdData, AlwaysAvailable, "{ Plot window / data buffer manipulation... }"},
{"hf", CmdHF, AlwaysAvailable, "{ High Frequency commands... }"},
{"hw", CmdHW, AlwaysAvailable, "{ Hardware commands... }"},
{"lf", CmdLF, AlwaysAvailable, "{ Low Frequency commands... }"},
{"emv", CmdEMV, AlwaysAvailable, "{ EMV iso14443 and iso7816... }"},
{"rem", CmdRem, AlwaysAvailable, "{ Add text to row in log file }"},
{"reveng", CmdRev, AlwaysAvailable, "{ Crc calculations from the RevEng software... }"},
{"script", CmdScript, AlwaysAvailable, "{ Scripting commands }"},
{"trace", CmdTrace, AlwaysAvailable, "{ Trace manipulation... }"},
{"mem", CmdFlashMem, IfPm3Flash, "{ Flash Memory manipulation... }"},
{"sc", CmdSmartcard, IfPm3Smartcard, "{ Smart card ISO7816 commands... }"},
{"quit", CmdQuit, AlwaysAvailable, ""},
{"exit", CmdQuit, AlwaysAvailable, "Exit program"},
{"help", CmdHelp, AlwaysAvailable, "This help. Use '<command> help' for details of a particular command."},
{"analyse", CmdAnalyse, AlwaysAvailable, "{ Analyse utils... }"},
{"data", CmdData, AlwaysAvailable, "{ Plot window / data buffer manipulation... }"},
{"hf", CmdHF, AlwaysAvailable, "{ High Frequency commands... }"},
{"hw", CmdHW, AlwaysAvailable, "{ Hardware commands... }"},
{"lf", CmdLF, AlwaysAvailable, "{ Low Frequency commands... }"},
{"emv", CmdEMV, AlwaysAvailable, "{ EMV iso14443 and iso7816... }"},
{"rem", CmdRem, AlwaysAvailable, "{ Add text to row in log file }"},
{"reveng", CmdRev, AlwaysAvailable, "{ Crc calculations from the RevEng software... }"},
{"script", CmdScript, AlwaysAvailable, "{ Scripting commands }"},
{"trace", CmdTrace, AlwaysAvailable, "{ Trace manipulation... }"},
{"mem", CmdFlashMem, IfPm3Flash, "{ Flash Memory manipulation... }"},
{"sc", CmdSmartcard, IfPm3Smartcard, "{ Smart card ISO7816 commands... }"},
{"usart", CmdUsart, IfPm3FpcUsartDevFromUsb, "{ USART commands... }"},
{"quit", CmdQuit, AlwaysAvailable, ""},
{"exit", CmdQuit, AlwaysAvailable, "Exit program"},
{NULL, NULL, NULL, NULL}
};

View File

@@ -34,6 +34,7 @@
#include "emv/cmdemv.h" // EMV
#include "cmdflashmem.h" // rdv40 flashmem commands
#include "cmdsmartcard.h" // rdv40 smart card ISO7816 commands
#include "cmdusart.h" // rdv40 FPC USART commands
int CommandReceived(char *Cmd);
command_t *getTopLevelCommandTable(void);

View File

@@ -43,18 +43,27 @@ bool IfPm3Smartcard(void) {
return pm3_capabilities.hw_available_smartcard;
}
bool IfPm3Fpc(void) {
bool IfPm3FpcUsart(void) {
if (!IfPm3Present())
return false;
return pm3_capabilities.compiled_with_fpc;
return pm3_capabilities.compiled_with_fpc_usart;
}
bool IfPm3FpcHost(void) {
bool IfPm3FpcUsartHost(void) {
if (!IfPm3Present())
return false;
if (!pm3_capabilities.compiled_with_fpc_host)
return pm3_capabilities.compiled_with_fpc_usart_host;
}
bool IfPm3FpcUsartDevFromUsb(void) {
// true if FPC USART developer support and if talking from USB-CDC interface
if (!IfPm3Present())
return false;
return pm3_capabilities.hw_available_fpc_host;
if (!pm3_capabilities.compiled_with_fpc_usart_dev)
return false;
if (conn.send_via_fpc_usart)
PrintAndLogEx(WARNING, "This command is not available via FPC, only via " _YELLOW_("USB-CDC"));
return !conn.send_via_fpc_usart;
}
bool IfPm3Lf(void) {
@@ -156,7 +165,7 @@ int CmdsParse(const command_t Commands[], const char *Cmd) {
if (Commands[i].IsAvailable()) {
break;
} else {
PrintAndLogEx(WARNING, "This command is only available in " _YELLOW_("online") "mode");
PrintAndLogEx(WARNING, "This command is " _YELLOW_("not available") "in this mode");
return PM3_ENOTIMPL;
}
}

View File

@@ -24,8 +24,9 @@ bool AlwaysAvailable(void);
bool IfPm3Present(void);
bool IfPm3Flash(void);
bool IfPm3Smartcard(void);
bool IfPm3Fpc(void);
bool IfPm3FpcHost(void);
bool IfPm3FpcUsart(void);
bool IfPm3FpcUsartHost(void);
bool IfPm3FpcUsartDevFromUsb(void);
bool IfPm3Lf(void);
bool IfPm3Hitag(void);
bool IfPm3Hfsniff(void);

View File

@@ -138,7 +138,7 @@ static void SendCommandNG_internal(uint16_t cmd, uint8_t *data, size_t len, bool
txBufferNG.pre.cmd = cmd;
memcpy(&txBufferNG.data, data, len);
if ((conn.send_via_fpc && conn.send_with_crc_on_fpc) || ((!conn.send_via_fpc) && conn.send_with_crc_on_usb)) {
if ((conn.send_via_fpc_usart && conn.send_with_crc_on_fpc) || ((!conn.send_via_fpc_usart) && conn.send_with_crc_on_usb)) {
uint8_t first, second;
compute_crc(CRC_14443_A, (uint8_t *)&txBufferNG, sizeof(PacketCommandNGPreamble) + len, &first, &second);
tx_post->crc = (first << 8) + second;
@@ -559,7 +559,7 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode,
conn.send_with_crc_on_usb = false;
conn.send_with_crc_on_fpc = true;
// "Session" flag, to tell via which interface next msgs should be sent: USB or FPC USART
conn.send_via_fpc = false;
conn.send_via_fpc_usart = false;
pthread_create(&USB_communication_thread, NULL, &uart_communication, &conn);
@@ -597,16 +597,15 @@ int TestProxmark(void) {
SendCommandNG(CMD_CAPABILITIES, NULL, 0);
if (WaitForResponseTimeoutW(CMD_PING, &resp, 1000, false)) {
memcpy(&pm3_capabilities, resp.data.asBytes, resp.length);
conn.send_via_fpc = pm3_capabilities.via_fpc;
conn.send_via_fpc_usart = pm3_capabilities.via_fpc;
conn.uart_speed = pm3_capabilities.baudrate;
PrintAndLogEx(INFO, "Communicating with PM3 over %s", conn.send_via_fpc ? _YELLOW_("FPC UART") : _YELLOW_("USB-CDC"));
if (conn.send_via_fpc) {
PrintAndLogEx(INFO, "Communicating with PM3 over %s", conn.send_via_fpc_usart ? _YELLOW_("FPC UART") : _YELLOW_("USB-CDC"));
if (conn.send_via_fpc_usart) {
PrintAndLogEx(INFO, "UART Serial baudrate: " _YELLOW_("%u") "\n", conn.uart_speed);
}
// reconfigure.
if (conn.send_via_fpc == false) {
if (conn.send_via_fpc_usart == false) {
#if defined(_WIN32)
pthread_mutex_lock(&spMutex);
#endif
@@ -669,7 +668,7 @@ void CloseProxmark(void) {
// ~ = 12000000 / USART_BAUD_RATE
// Let's take 2x (maybe we need more for BT link?)
static size_t communication_delay(void) {
if (conn.send_via_fpc) // needed also for Windows USB USART??
if (conn.send_via_fpc_usart) // needed also for Windows USB USART??
return 2 * (12000000 / conn.uart_speed);
return 100;
}

View File

@@ -46,7 +46,7 @@ typedef struct {
bool send_with_crc_on_usb;
bool send_with_crc_on_fpc;
// "Session" flag, to tell via which interface next msgs are sent: USB or FPC USART
bool send_via_fpc;
bool send_via_fpc_usart;
// To memorise baudrate
uint32_t uart_speed;
} communication_arg_t;