From 4763eb417a116e554c420a2cc9541d457226c9fb Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 14 Apr 2019 11:05:32 +0200 Subject: [PATCH 1/7] fix coverity warnings --- client/cmdlf.c | 3 --- client/proxguiqt.cpp | 11 +++++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/client/cmdlf.c b/client/cmdlf.c index 9dfa16640..3243d60af 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -189,9 +189,6 @@ int CmdLFCommandRead(const char *Cmd) { int CmdFlexdemod(const char *Cmd) { (void)Cmd; // Cmd is not used so far - if (GraphTraceLen < 0) - return 0; - #ifndef LONG_WAIT #define LONG_WAIT 100 #endif diff --git a/client/proxguiqt.cpp b/client/proxguiqt.cpp index 2cf2d0200..e2ef546f6 100644 --- a/client/proxguiqt.cpp +++ b/client/proxguiqt.cpp @@ -276,9 +276,11 @@ QColor Plot::getColor(int graphNum) { void Plot::setMaxAndStart(int *buffer, size_t len, QRect plotRect) { if (len == 0) return; - startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint)); - if (startMax < 0) { - startMax = 0; + startMax = 0; + if (plotRect.right() >= plotRect.left() + 40) { + uint32_t t = (plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint; + if (len >= t) + startMax = len - t; } if (GraphStart > startMax) { GraphStart = startMax; @@ -470,9 +472,6 @@ void Plot::paintEvent(QPaintEvent *event) { painter.setFont(QFont("Courier New", 10)); - if (GraphStart < 0) - GraphStart = 0; - if (CursorAPos > GraphTraceLen) CursorAPos = 0; if (CursorBPos > GraphTraceLen) From e44fcb52d6bc09051ff24d6e344c275bbcdd7d5c Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 14 Apr 2019 11:07:35 +0200 Subject: [PATCH 2/7] fix: usart needs those pins. (@ryan) --- armsrc/fpgaloader.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c index b70bad2e4..2474d7026 100644 --- a/armsrc/fpgaloader.c +++ b/armsrc/fpgaloader.c @@ -449,6 +449,9 @@ void FpgaWriteConfWord(uint8_t v) { // the samples from the ADC always flow through the FPGA. //----------------------------------------------------------------------------- void SetAdcMuxFor(uint32_t whichGpio) { + +#ifndef WITH_FPC + // When compiled without FPC support AT91C_BASE_PIOA->PIO_OER = GPIO_MUXSEL_HIPKD | GPIO_MUXSEL_LOPKD | @@ -463,9 +466,15 @@ void SetAdcMuxFor(uint32_t whichGpio) { LOW(GPIO_MUXSEL_HIPKD); LOW(GPIO_MUXSEL_LOPKD); -#ifndef WITH_FPC LOW(GPIO_MUXSEL_HIRAW); LOW(GPIO_MUXSEL_LORAW); + +#else + // FPC serial uses HIRAW/LOWRAW pins, so they are excluded here. + AT91C_BASE_PIOA->PIO_OER = GPIO_MUXSEL_HIPKD | GPIO_MUXSEL_LOPKD; + AT91C_BASE_PIOA->PIO_PER = GPIO_MUXSEL_HIPKD | GPIO_MUXSEL_LOPKD; + LOW(GPIO_MUXSEL_HIPKD); + LOW(GPIO_MUXSEL_LOPKD); #endif HIGH(whichGpio); From fc0a62de18c2bb58c7b2f0293c5949c913774af8 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 14 Apr 2019 11:08:44 +0200 Subject: [PATCH 3/7] Fix: USART - better RX/TX with one dma bank and wait loops (@ryan) --- common/usart.c | 70 +++++++++++++++++++++++++++++++++++++++++++++----- common/usart.h | 5 ++++ 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/common/usart.c b/common/usart.c index 8680d500a..cd657a2b1 100644 --- a/common/usart.c +++ b/common/usart.c @@ -42,7 +42,7 @@ void usart_close(void) { static uint8_t us_inbuf[sizeof(UsbCommand)]; static uint8_t us_outbuf[sizeof(UsbCommand)]; - +/* // transfer from client to device inline int16_t usart_readbuffer(uint8_t *data) { uint32_t rcr = pUS1->US_RCR; @@ -58,6 +58,38 @@ inline int16_t usart_readbuffer(uint8_t *data) { return 0; } } +*/ + +uint8_t check = 0; +inline int16_t usart_readbuffer(uint8_t *data) { + // Check if the first PDC bank is free + if (pUS1->US_RCR == 0) { + pUS1->US_RPR = (uint32_t)data; + pUS1->US_RCR = sizeof(UsbCommand); + pUS1->US_PTCR = AT91C_PDC_RXTEN | AT91C_PDC_TXTEN; + check = 0; + return 2; + } else { + return 0; + } +} + +void usart_readcheck(uint8_t *data,size_t len) { + if (pUS1->US_RCR 300000){ + pUS1->US_RPR = (uint32_t)data; + pUS1->US_RCR = len; + check = 0; + } + } else { + check = 0; + } +} inline bool usart_dataavailable(void) { return pUS1->US_RCR < sizeof(us_inbuf); @@ -66,14 +98,14 @@ inline bool usart_dataavailable(void) { inline int16_t usart_readcommand(uint8_t *data) { if (pUS1->US_RCR == 0) return usart_readbuffer(data); - else + return 0; } inline bool usart_commandavailable(void) { - return pUS1->US_RCR == 0; + return (pUS1->US_RCR == 0); } - +/* // transfer from device to client inline int16_t usart_writebuffer(uint8_t *data, size_t len) { @@ -90,6 +122,31 @@ inline int16_t usart_writebuffer(uint8_t *data, size_t len) { return 0; } } +*/ + +// transfer from device to client +inline int16_t usart_writebuffer(uint8_t *data, size_t len) { + + while (pUS1->US_TCR && pUS1->US_TNCR) {}; + + // Check if the first PDC bank is free + if (pUS1->US_TCR == 0) { + memcpy(us_outbuf, data, len); + pUS1->US_TPR = (uint32_t)us_outbuf; + pUS1->US_TCR = sizeof(us_outbuf); + pUS1->US_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTEN; + } + // Check if the second PDC bank is free + else if (pUS1->US_TNCR == 0) { + memcpy(us_outbuf, data, len); + pUS1->US_TNPR = (uint32_t)us_outbuf; + pUS1->US_TNCR = sizeof(us_outbuf); + pUS1->US_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTEN; + } + //wait until finishing transfer + while (pUS1->US_TCR && pUS1->US_TNCR) {}; + return 0; +} void usart_init(void) { @@ -141,11 +198,12 @@ void usart_init(void) { pUS1->US_RNPR = (uint32_t)0; pUS1->US_RNCR = 0; - // re-enable receiver / transmitter pUS1->US_CR = (AT91C_US_RXEN | AT91C_US_TXEN); + // ready to receive pUS1->US_RPR = (uint32_t)us_inbuf; - pUS1->US_RCR = sizeof(us_inbuf); + pUS1->US_RCR = 0; + pUS1->US_RNCR = 0; pUS1->US_PTCR = AT91C_PDC_RXTEN; } diff --git a/common/usart.h b/common/usart.h index f98424841..f01968055 100644 --- a/common/usart.h +++ b/common/usart.h @@ -3,6 +3,9 @@ #include #include "proxmark3.h" +#include "../armsrc/ticks.h" // startcountus + +#define AT91_BAUD_RATE 115200 void usart_init(void); void usart_close(void); @@ -11,5 +14,7 @@ int16_t usart_readbuffer(uint8_t *data); int16_t usart_writebuffer(uint8_t *data, size_t len); bool usart_dataavailable(void); int16_t usart_readcommand(uint8_t *data); +void usart_readcheck(uint8_t *data,size_t len); + bool usart_commandavailable(void); #endif From dd404a67a10345d98caeb65b9d133a9f42ac0568 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 14 Apr 2019 11:09:31 +0200 Subject: [PATCH 4/7] Fix: USART - default speeds is lower (@ryan) --- client/proxmark3.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/proxmark3.c b/client/proxmark3.c index 600d975e3..ffb8b295f 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -364,8 +364,13 @@ int main(int argc, char *argv[]) { } } + // default speed for USB 460800, USART(FPC serial) 115200 baud if (speed == 0) +#ifdef WITH_FPC + speed = 115200; +#else speed = 460800; +#endif // If the user passed the filename of the 'script' to execute, get it from last parameter if (lastarg) { From 664434dfbac618d777306daa0719bf76992bcd43 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 14 Apr 2019 11:10:16 +0200 Subject: [PATCH 5/7] Fix: USART calls rx/tx --- armsrc/appmain.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index fd0d4cafc..223bd2155 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1136,7 +1136,7 @@ void UsbPacketReceived(uint8_t *packet, int len) { uint8_t my_rx[sizeof(UsbCommand)]; while (!BUTTON_PRESS() && !usb_poll_validate_length()) { LED_B_INV(); - if (usart_readbuffer(my_rx, sizeof(UsbCommand)) ) { + if (usart_readbuffer(my_rx) ) { //UsbPacketReceived(my_rx, sizeof(my_rx)); UsbCommand *my = (UsbCommand *)my_rx; @@ -1565,10 +1565,11 @@ void __attribute__((noreturn)) AppMain(void) { } #ifdef WITH_FPC_HOST // Check if there is a FPC packet available - if (usart_readcommand(rx) > 0) { + if (usart_readbuffer(rx)) { reply_via_fpc = 1; UsbPacketReceived(rx, sizeof(rx)); } + usart_readcheck(rx, sizeof(rx)); #endif // Press button for one second to enter a possible standalone mode From 61a42df4f63e737ec73c9aab390e4731cdac0dd0 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 14 Apr 2019 11:11:42 +0200 Subject: [PATCH 6/7] textual --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82ff79424..71f61eaf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Fix serial of FPC. (@ryan) - Fix 'data shiftgraphzero' corrupting end of GraphBuffer (@doegox) - Fix 'hf legic info' - unsegmented card now uses card size to calc remaining length (@iceman) - Add 36bit HID format, extend calcWiegand() to include oem bits ((@davidbeauchamp) From e9db49be1e9d8ff3946ffabc6ac260146005faca Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 14 Apr 2019 11:13:31 +0200 Subject: [PATCH 7/7] chg: 'data rawdemod' - enhanced command params --- client/cmddata.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/cmddata.c b/client/cmddata.c index 0112565a7..1a38fc00f 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -1314,12 +1314,12 @@ static int CmdRawDemod(const char *Cmd) { str_lower((char *)Cmd); - if (str_startswith(Cmd, "fs")) ans = CmdFSKrawdemod(Cmd + 2); + if (str_startswith(Cmd, "fs") || Cmd[0] == 'f' ) ans = CmdFSKrawdemod(Cmd+2); else if (str_startswith(Cmd, "ab")) ans = Cmdaskbiphdemod(Cmd + 2); else if (str_startswith(Cmd, "am")) ans = Cmdaskmandemod(Cmd + 2); else if (str_startswith(Cmd, "ar")) ans = Cmdaskrawdemod(Cmd + 2); - else if (str_startswith(Cmd, "nr")) ans = CmdNRZrawDemod(Cmd + 2); - else if (str_startswith(Cmd, "p1")) ans = CmdPSK1rawDemod(Cmd + 2); + else if (str_startswith(Cmd, "nr") || Cmd[0] == 'n') ans = CmdNRZrawDemod(Cmd+2); + else if (str_startswith(Cmd, "p1") || Cmd[0] == 'p') ans = CmdPSK1rawDemod(Cmd + 2); else if (str_startswith(Cmd, "p2")) ans = CmdPSK2rawDemod(Cmd + 2); else PrintAndLogEx(WARNING, "Unknown modulation entered - see help ('h') for parameter structure");