From 3a776ecf3ab71567de2a1e25c3b593f1b3fea44a Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 13 Sep 2019 10:17:58 +0200 Subject: [PATCH 1/3] chg samyrun - dual leds flash after state changes --- armsrc/Standalone/lf_samyrun.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/armsrc/Standalone/lf_samyrun.c b/armsrc/Standalone/lf_samyrun.c index f71fef393..df9812869 100644 --- a/armsrc/Standalone/lf_samyrun.c +++ b/armsrc/Standalone/lf_samyrun.c @@ -78,7 +78,7 @@ void RunMod() { WAIT_BUTTON_RELEASED(); // record - DbpString("[=] starting recording"); + DbpString("[=] start recording"); // findone, high, low, no ledcontrol (A) uint32_t hi = 0, lo = 0; @@ -86,16 +86,16 @@ void RunMod() { high[selected] = hi; low[selected] = lo; - Dbprintf("[=] recorded bank %x | %x%08x", selected, high[selected], low[selected]); + Dbprintf("[=] recorded %x | %x%08x", selected, high[selected], low[selected]); // got nothing. blink and loop. if ( hi == 0 && lo == 0 ) { SpinErr( (selected == 0) ? LED_A : LED_B, 100, 12); - Dbprintf("[=] recorded nothing, looping"); + DbpString("[=] only got zeros, retry recording after click"); continue; } - SpinErr( (select==0) ? LED_A : LED_B, 250, 2); + SpinErr( (selected == 0) ? LED_A : LED_B, 250, 2); state = STATE_SIM; continue; @@ -109,7 +109,11 @@ void RunMod() { // high, low, no led control(A) no time limit CmdHIDsimTAGEx(high[selected], low[selected], false, -1); - SpinErr( LED_C, 250, 2); + + DbpString("[=] simulating done"); + + uint8_t leds = ((selected == 0) ? LED_A : LED_B) | LED_C; + SpinErr( leds , 250, 2); state = STATE_CLONE; continue; @@ -119,17 +123,21 @@ void RunMod() { LED_D_ON(); // clone WAIT_BUTTON_RELEASED(); - Dbprintf("[=] cloning %x | %x%08x", selected, high[selected], low[selected]); + Dbprintf("[=] cloning %x | %x%08x", selected, high[selected], low[selected]); // high2, high, low, no longFMT CopyHIDtoT55x7(0, high[selected], low[selected], 0); + + DbpString("[=] cloned done"); + state = STATE_READ; - SpinErr( LED_D, 250, 2); + uint8_t leds = ((selected == 0) ? LED_A : LED_B) | LED_D; + SpinErr(leds, 250, 2); selected = (selected + 1) % OPTS; LEDsoff(); } } - DbpString("[=] exiting samyrun"); + DbpString("[=] You can take shell back :) ..."); LEDsoff(); } From 3dc4774f20fc2978613a4931b8cf42703ba8f6fd Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 13 Sep 2019 10:35:17 +0200 Subject: [PATCH 2/3] simplify fcAll --- armsrc/lfops.c | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/armsrc/lfops.c b/armsrc/lfops.c index e5204a5a5..341b98483 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -941,12 +941,10 @@ static void fcSTT(int *n) { } // compose fc/X fc/Y waveform (FSKx) -static uint8_t fcAll(uint8_t fc, int *n, uint8_t clock, uint16_t *modCnt) { +static void fcAll(uint8_t fc, int *n, uint8_t clock, int16_t *remainder) { uint8_t *dest = BigBuf_get_addr(); uint8_t halfFC = fc >> 1; - uint8_t wavesPerClock = clock / fc; - uint8_t mod = clock % fc; //modifier - + uint8_t wavesPerClock = (clock + *remainder) / fc; // loop through clock - step field clock for (uint8_t idx = 0; idx < wavesPerClock; idx++) { // put 1/2 FC length 1's and 1/2 0's per field clock wave (to create the wave) @@ -954,27 +952,14 @@ static uint8_t fcAll(uint8_t fc, int *n, uint8_t clock, uint16_t *modCnt) { memset(dest + (*n) + (fc - halfFC), 1, halfFC); *n += fc; } - if (mod > 0) { - uint8_t modAdj = fc / mod; //how often to apply modifier - bool modAdjOk = !(fc % mod); //if (fc % mod==0) modAdjOk = true; - (*modCnt)++; - - if (modAdjOk) { //fsk2 - if ((*modCnt % modAdj) == 0) { //if 4th 8 length wave in a rf/50 add extra 8 length wave - memset(dest + (*n), 0, fc - halfFC); - memset(dest + (*n) + (fc - halfFC), 1, halfFC); - *n += fc; - } - } -/* This code interfers with FSK2 and I don't see any example of FSK1 simulation in the code... - if (!modAdjOk) { //fsk1 - memset(dest + (*n), 0, mod - (mod >> 1)); - memset(dest + (*n) + (mod - (mod >> 1)), 1, mod >> 1); - *n += mod; - } -*/ + *remainder = (clock + *remainder) % fc; + // if we've room for more than a half wave, add a full wave and use negative remainder + if (*remainder > halfFC) { + memset(dest + (*n), 0, fc - halfFC); //in case of odd number use extra here + memset(dest + (*n) + (fc - halfFC), 1, halfFC); + *n += fc; + *remainder -= fc; } - return mod; } // prepare a waveform pattern in the buffer based on the ID given then @@ -1061,8 +1046,7 @@ void CmdFSKsimTAG(uint8_t fchigh, uint8_t fclow, uint8_t separator, uint8_t clk, set_tracing(false); int n = 0, i = 0; - uint16_t modCnt = 0; - uint8_t mod = 0; + int16_t remainder = 0; if (separator) { //int fsktype = ( fchigh == 8 && fclow == 5) ? 1 : 2; @@ -1070,9 +1054,9 @@ void CmdFSKsimTAG(uint8_t fchigh, uint8_t fclow, uint8_t separator, uint8_t clk, } for (i = 0; i < bitslen; i++) { if (bits[i]) - mod = fcAll(fchigh, &n, clk+mod, &modCnt); + fcAll(fchigh, &n, clk, &remainder); else - mod = fcAll(fclow, &n, clk+mod, &modCnt); + fcAll(fclow, &n, clk, &remainder); } WDT_HIT(); From 270d0821b5563c9a7635df25d2e887639644ea3b Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 13 Sep 2019 12:11:56 +0200 Subject: [PATCH 3/3] chg: 'data print i' - new param I, inverts the demod buffer --- client/cmddata.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/client/cmddata.c b/client/cmddata.c index 9465c63ac..18e91c699 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -36,6 +36,7 @@ static int usage_data_printdemodbuf(void) { PrintAndLogEx(NORMAL, "Usage: data printdemodbuffer x o l "); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h This help"); + PrintAndLogEx(NORMAL, " i invert Demodbuffer before printing"); PrintAndLogEx(NORMAL, " x output in hex (omit for binary output)"); PrintAndLogEx(NORMAL, " o enter offset in # of bits"); PrintAndLogEx(NORMAL, " l enter length to print in # of bits or hex characters respectively"); @@ -251,7 +252,6 @@ static int usage_data_fsktonrz() { return PM3_SUCCESS; } - //set the demod buffer with given array of binary (one bit per byte) //by marshmellow void setDemodBuff(uint8_t *buff, size_t size, size_t start_idx) { @@ -404,6 +404,7 @@ int CmdPrintDemodBuff(const char *Cmd) { bool hexMode = false; bool errors = false; bool lstrip = false; + bool invert = false; uint32_t offset = 0; uint32_t length = 512; char cmdp = 0; @@ -427,7 +428,11 @@ int CmdPrintDemodBuff(const char *Cmd) { break; case 's': lstrip = true; - cmdp ++; + cmdp++; + break; + case 'i': + invert = true; + cmdp++; break; default: PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); @@ -453,6 +458,18 @@ int CmdPrintDemodBuff(const char *Cmd) { } length = (length > (DemodBufferLen - offset)) ? DemodBufferLen - offset : length; + if (invert) { + char *buf = (char *)(DemodBuffer + offset); + for (uint32_t i = 0; i < length; i++) { + if ( buf[i] == 1 ) + buf[i] = 0; + else { + if ( buf[i] == 0 ) + buf[i] = 1; + } + } + } + if (hexMode) { char *buf = (char *)(DemodBuffer + offset); char hex[512] = {0x00}; @@ -2160,7 +2177,6 @@ static command_t CommandTable[] = { {"dec", CmdDec, AlwaysAvailable, "Decimate samples"}, {"detectclock", CmdDetectClockRate, AlwaysAvailable, "[] Detect ASK, FSK, NRZ, PSK clock rate of wave in GraphBuffer"}, {"fsktonrz", CmdFSKToNRZ, AlwaysAvailable, "Convert fsk2 to nrz wave for alternate fsk demodulating (for weak fsk)"}, - {"getbitstream", CmdGetBitStream, AlwaysAvailable, "Convert GraphBuffer's >=1 values to 1 and <1 to 0"}, {"grid", CmdGrid, AlwaysAvailable, " -- overlay grid on graph window, use zero value to turn off either"}, {"hexsamples", CmdHexsamples, IfPm3Present, " [] -- Dump big buffer as hex bytes"},