From: Martin Holst Swende Date: Sun, 15 Nov 2015 12:22:26 +0000 (+0100) Subject: Merge pull request #143 from marshmellow42/master X-Git-Tag: v2.3.0~15 X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/9983a929430904ddeb18ec3aded0afad964272ba?hp=14331320c4fe733b60bed9e638be0989286a41e4 Merge pull request #143 from marshmellow42/master lfops cleanup, t55xx additions/fixes, PCF7931 input cleanup --- diff --git a/.gitignore b/.gitignore index 880c092f..fa74326e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # .gitignore # don't push these files to the repository +.history *.log *.eml *.o diff --git a/Makefile b/Makefile index 0e065b41..bafd8161 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ help: @echo + all - Make bootrom, armsrc and the OS-specific host directory @echo + client - Make only the OS-specific host directory @echo + flash-bootrom - Make bootrom and flash it - @echo + flash-os - Make armsrc and flash os (includes fpga) + @echo + flash-os - Make armsrc and flash os \(includes fpga\) @echo + flash-all - Make bootrom and armsrc and flash bootrom and os image @echo + clean - Clean in bootrom, armsrc and the OS-specific host directory diff --git a/armsrc/hfsnoop.c b/armsrc/hfsnoop.c index b7d69013..56774bd0 100644 --- a/armsrc/hfsnoop.c +++ b/armsrc/hfsnoop.c @@ -7,7 +7,6 @@ static void RAMFUNC optimizedSnoop(void); static void RAMFUNC optimizedSnoop(void) { - BigBuf_free(); int n = BigBuf_max_traceLen() / sizeof(uint16_t); // take all memory uint16_t *dest = (uint16_t *)BigBuf_get_addr(); @@ -29,7 +28,7 @@ static void RAMFUNC optimizedSnoop(void) void HfSnoop(int samplesToSkip, int triggersToSkip) { - Dbprintf("Skipping first %d sample pairs, Skipping %d triggers.\n", samplesToSkip, triggersToSkip); + Dbprintf("Skipping first %d sample pairs, Skipping %d triggers.", samplesToSkip, triggersToSkip); bool trigger_cnt; LED_D_ON(); // Select correct configs @@ -41,6 +40,9 @@ void HfSnoop(int samplesToSkip, int triggersToSkip) FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SNOOP); SpinDelay(100); + BigBuf_free(); + BigBuf_Clear(); + AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(16); // Setting Frame Mode For better performance on high speed data transfer. trigger_cnt = 0; @@ -49,24 +51,25 @@ void HfSnoop(int samplesToSkip, int triggersToSkip) WDT_HIT(); if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) { r = (uint16_t)AT91C_BASE_SSC->SSC_RHR; - if (!(trigger_cnt == triggersToSkip) && ( (r >> 8) >= 240)) + r = MAX(r & 0xff, r >> 8); + if (r >= 240) { - Dbprintf("Trigger kicked! Value: %d.", r >> 8); - trigger_cnt++; - break; + if (++trigger_cnt > triggersToSkip) { + break; + } } } } + if(!BUTTON_PRESS()) { - Dbprintf("Trigger kicked! Value: %d, Dumping Samples Hispeed now.", r >> 8); int waitcount = samplesToSkip; // lets wait 40000 ticks of pck0 while(waitcount != 0) { if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) { waitcount--; } } - optimizedSnoop(); + Dbprintf("Trigger kicked! Value: %d, Dumping Samples Hispeed now.", r); } DbpString("HF Snoop end"); diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index cba179ec..81716db3 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -352,16 +352,16 @@ int CmdHF14AReader(const char *Cmd) PrintAndLog(" x0 -> <1 kByte"); break; case 0x01: - PrintAndLog(" x0 -> 1 kByte"); + PrintAndLog(" x1 -> 1 kByte"); break; case 0x02: - PrintAndLog(" x0 -> 2 kByte"); + PrintAndLog(" x2 -> 2 kByte"); break; case 0x03: - PrintAndLog(" x0 -> 4 kByte"); + PrintAndLog(" x3 -> 4 kByte"); break; case 0x04: - PrintAndLog(" x0 -> 8 kByte"); + PrintAndLog(" x4 -> 8 kByte"); break; } switch (card.ats[pos + 3] & 0xf0) { diff --git a/client/cmdmain.c b/client/cmdmain.c index deced558..7bba80f4 100644 --- a/client/cmdmain.c +++ b/client/cmdmain.c @@ -42,15 +42,15 @@ static int cmd_tail;//Starts as 0 static command_t CommandTable[] = { - {"help", CmdHelp, 1, "This help. Use ' help' for details of a particular command."}, - {"data", CmdData, 1, "{ Plot window / data buffer manipulation... }"}, - {"hf", CmdHF, 1, "{ High Frequency commands... }"}, - {"hw", CmdHW, 1, "{ Hardware commands... }"}, - {"lf", CmdLF, 1, "{ Low Frequency commands... }"}, - {"script", CmdScript, 1,"{ Scripting commands }"}, - {"quit", CmdQuit, 1, "Exit program"}, - {"exit", CmdQuit, 1, "Exit program"}, - {NULL, NULL, 0, NULL} + {"help", CmdHelp, 1, "This help. Use ' help' for details of a particular command."}, + {"data", CmdData, 1, "{ Plot window / data buffer manipulation... }"}, + {"hf", CmdHF, 1, "{ High Frequency commands... }"}, + {"hw", CmdHW, 1, "{ Hardware commands... }"}, + {"lf", CmdLF, 1, "{ Low Frequency commands... }"}, + {"script", CmdScript, 1, "{ Scripting commands }"}, + {"quit", CmdQuit, 1, "Exit program"}, + {"exit", CmdQuit, 1, "Exit program"}, + {NULL, NULL, 0, NULL} }; command_t* getTopLevelCommandTable() @@ -65,8 +65,7 @@ int CmdHelp(const char *Cmd) int CmdQuit(const char *Cmd) { - exit(0); - return 0; + return 99; } /** * @brief This method should be called when sending a new command to the pm3. In case any old @@ -164,8 +163,8 @@ bool WaitForResponse(uint32_t cmd, UsbCommand* response) { // Entry point into our code: called whenever the user types a command and // then presses Enter, which the full command line that they typed. //----------------------------------------------------------------------------- -void CommandReceived(char *Cmd) { - CmdsParse(CommandTable, Cmd); +int CommandReceived(char *Cmd) { + return CmdsParse(CommandTable, Cmd); } diff --git a/client/cmdmain.h b/client/cmdmain.h index 0cf2b35d..500320ee 100644 --- a/client/cmdmain.h +++ b/client/cmdmain.h @@ -14,7 +14,7 @@ #include "usb_cmd.h" #include "cmdparser.h" void UsbCommandReceived(UsbCommand *UC); -void CommandReceived(char *Cmd); +int CommandReceived(char *Cmd); bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout); bool WaitForResponse(uint32_t cmd, UsbCommand* response); void clearCommandBuffer(); diff --git a/client/cmdparser.c b/client/cmdparser.c index 6910e86a..32508997 100644 --- a/client/cmdparser.c +++ b/client/cmdparser.c @@ -15,6 +15,7 @@ #include "cmdparser.h" #include "proxmark3.h" + void CmdsHelp(const command_t Commands[]) { if (Commands[0].Name == NULL) @@ -28,48 +29,51 @@ void CmdsHelp(const command_t Commands[]) } } -void CmdsParse(const command_t Commands[], const char *Cmd) + +int CmdsParse(const command_t Commands[], const char *Cmd) { - if(strcmp( Cmd, "XX_internal_command_dump_XX") == 0) - {// Help dump children - dumpCommandsRecursive(Commands, 0); - return; - } - if(strcmp( Cmd, "XX_internal_command_dump_markdown_XX") == 0) - {// Markdown help dump children - dumpCommandsRecursive(Commands, 1); - return; - } - char cmd_name[32]; - int len = 0; - memset(cmd_name, 0, 32); - sscanf(Cmd, "%31s%n", cmd_name, &len); - int i = 0; - while (Commands[i].Name && strcmp(Commands[i].Name, cmd_name)) - ++i; + if(strcmp( Cmd, "XX_internal_command_dump_XX") == 0) + {// Help dump children + dumpCommandsRecursive(Commands, 0); + return 0; + } + if(strcmp( Cmd, "XX_internal_command_dump_markdown_XX") == 0) + {// Markdown help dump children + dumpCommandsRecursive(Commands, 1); + return 0; + } + char cmd_name[32]; + int len = 0; + memset(cmd_name, 0, 32); + sscanf(Cmd, "%31s%n", cmd_name, &len); + int i = 0; + while (Commands[i].Name && strcmp(Commands[i].Name, cmd_name)) + ++i; - /* try to find exactly one prefix-match */ - if(!Commands[i].Name) { - int last_match = 0; - int matches = 0; - - for(i=0;Commands[i].Name;i++) { - if( !strncmp(Commands[i].Name, cmd_name, strlen(cmd_name)) ) { - last_match = i; - matches++; - } - } - if(matches == 1) i=last_match; - } + /* try to find exactly one prefix-match */ + if(!Commands[i].Name) { + int last_match = 0; + int matches = 0; - if (Commands[i].Name) { - while (Cmd[len] == ' ') - ++len; - Commands[i].Parse(Cmd + len); - } else { - // show help for selected hierarchy or if command not recognised - CmdsHelp(Commands); - } + for(i=0;Commands[i].Name;i++) { + if( !strncmp(Commands[i].Name, cmd_name, strlen(cmd_name)) ) { + last_match = i; + matches++; + } + } + if(matches == 1) i=last_match; + } + + if (Commands[i].Name) { + while (Cmd[len] == ' ') + ++len; + return Commands[i].Parse(Cmd + len); + } else { + // show help for selected hierarchy or if command not recognised + CmdsHelp(Commands); + } + + return 0; } char pparent[512] = {0}; diff --git a/client/cmdparser.h b/client/cmdparser.h index b7997ecc..5217d04b 100644 --- a/client/cmdparser.h +++ b/client/cmdparser.h @@ -24,7 +24,7 @@ typedef struct command_s // Print help for each command in the command array void CmdsHelp(const command_t Commands[]); // Parse a command line -void CmdsParse(const command_t Commands[], const char *Cmd); +int CmdsParse(const command_t Commands[], const char *Cmd); void dumpCommandsRecursive(const command_t cmds[], int markdown); #endif diff --git a/client/proxmark3.c b/client/proxmark3.c index 2f370308..f184d9e9 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -155,12 +155,11 @@ static void *main_loop(void *targ) { cmd[strlen(cmd) - 1] = 0x00; if (cmd[0] != 0x00) { - if (strncmp(cmd, "quit", 4) == 0) { - exit(0); + int ret = CommandReceived(cmd); + add_history(cmd); + if (ret == 99) { // exit or quit break; } - CommandReceived(cmd); - add_history(cmd); } free(cmd); } else { @@ -223,7 +222,7 @@ int main(int argc, char* argv[]) { .usb_present = 0, .script_cmds_file = NULL }; - pthread_t main_loop_t; + pthread_t main_loop_threat; sp = uart_open(argv[1]); @@ -258,18 +257,20 @@ int main(int argc, char* argv[]) { // create a mutex to avoid interlacing print commands from our different threads pthread_mutex_init(&print_lock, NULL); - pthread_create(&main_loop_t, NULL, &main_loop, &marg); + pthread_create(&main_loop_threat, NULL, &main_loop, &marg); InitGraphics(argc, argv); MainGraphics(); - pthread_join(main_loop_t, NULL); + pthread_join(main_loop_threat, NULL); // Clean up the port - uart_close(sp); - + if (offline == 0) { + uart_close(sp); + } + // clean up mutex pthread_mutex_destroy(&print_lock); - - return 0; + + exit(0); }