From: marshmellow42 Date: Tue, 22 Dec 2015 04:56:55 +0000 (-0500) Subject: Merge remote-tracking branch 'upstream/master' X-Git-Tag: v2.3.0~10^2~5 X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/254687260c3f8262de56ec93ff089d06d083483e?hp=c578d3412cd02034c3c16b7a84c5689d9813fb2d Merge remote-tracking branch 'upstream/master' --- diff --git a/client/cmddata.c b/client/cmddata.c index e8b77d1d..05c495d9 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -944,35 +944,32 @@ int FSKrawDemod(const char *Cmd, bool verbose) { //raw fsk demod no manchester decoding no start bit finding just get binary from wave uint8_t rfLen, invert, fchigh, fclow; - //set defaults //set options from parameters entered with the command - rfLen = param_get8ex(Cmd, 0, 0, 10); - invert = param_get8ex(Cmd, 1, 0, 10); - fchigh = param_get8ex(Cmd, 2, 0, 10); - fclow = param_get8ex(Cmd, 3, 0, 10); - + rfLen = param_get8(Cmd, 0); + invert = param_get8(Cmd, 1); + fchigh = param_get8(Cmd, 2); + fclow = param_get8(Cmd, 3); if (strlen(Cmd)>0 && strlen(Cmd)<=2) { if (rfLen==1){ invert = 1; //if invert option only is used rfLen = 0; } } - uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0}; size_t BitLen = getFromGraphBuf(BitStream); if (BitLen==0) return 0; //get field clock lengths - uint16_t fcs=0; + uint8_t fc1=0, fc2=0, rf1=0; if (!fchigh || !fclow) { - fcs = countFC(BitStream, BitLen, 1); - if (!fcs) { - fchigh = 10; - fclow = 8; - } else { - fchigh = (fcs >> 8) & 0x00FF; - fclow = fcs & 0x00FF; + uint8_t ans = fskClocks(&fc1, &fc2, &rf1, false); + if (ans == 0) { + if (g_debugMode) PrintAndLog("\nError: cannot detect valid fsk field clocks"); + return 0; // can't detect field clock } + fchigh = fc1; + fclow = fc2; + if (rfLen == 0) rfLen = rf1; } //get bit clock length if (!rfLen){ @@ -985,7 +982,7 @@ int FSKrawDemod(const char *Cmd, bool verbose) // Now output the bitstream to the scrollback by line of 16 bits if (verbose || g_debugMode) { - PrintAndLog("\nUsing Clock:%u, invert:%u, fchigh:%u, fclow:%u", rfLen, invert, fchigh, fclow); + PrintAndLog("\nUsing Clock:%d, invert:%d, fchigh:%d, fclow:%d", rfLen, invert, fchigh, fclow); PrintAndLog("%s decoded bitstream:",GetFSKType(fchigh,fclow,invert)); printDemodBuff(); } diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 868126c9..0d277d06 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -183,7 +183,6 @@ int CmdT55xxSetConfig(const char *Cmd) { uint8_t bitRate = 0; uint8_t rates[9] = {8,16,32,40,50,64,100,128,0}; uint8_t cmdp = 0; - config.Q5 = FALSE; bool errors = FALSE; while(param_getchar(Cmd, cmdp) != 0x00 && !errors) { @@ -469,7 +468,7 @@ bool tryDetectModulation(){ if (GetFskClock("", FALSE, FALSE)){ fskClocks(&fc1, &fc2, &clk, FALSE); - if ( FSKrawDemod("0 0", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){ + if ( FSKrawDemod("0 0", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) { tests[hits].modulation = DEMOD_FSK; if (fc1==8 && fc2 == 5) tests[hits].modulation = DEMOD_FSK1a; @@ -486,7 +485,6 @@ bool tryDetectModulation(){ tests[hits].modulation = DEMOD_FSK1; else if (fc1 == 10 && fc2 == 8) tests[hits].modulation = DEMOD_FSK2a; - tests[hits].bitrate = bitRate; tests[hits].inverted = TRUE; tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer); @@ -597,6 +595,7 @@ bool tryDetectModulation(){ config.inverted = tests[0].inverted; config.offset = tests[0].offset; config.block0 = tests[0].block0; + config.Q5 = tests[0].Q5; printConfiguration( config ); return TRUE; } @@ -672,6 +671,15 @@ bool testQ5Modulation(uint8_t mode, uint8_t modread){ return FALSE; } +int convertQ5bitRate(uint8_t bitRateRead) { + uint8_t expected[] = {8, 16, 32, 40, 50, 64, 100, 128}; + for (int i=0; i<8; i++) + if (expected[i] == bitRateRead) + return i; + + return -1; +} + bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk){ if ( DemodBufferLen < 64 ) return FALSE; @@ -683,12 +691,12 @@ bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk){ uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key uint8_t resv = PackBits(si, 8, DemodBuffer); si += 8; // 2nibble must be zeroed. - if (safer != 0x6) continue; + if (safer != 0x6 && safer != 0x9) continue; if ( resv > 0x00) continue; //uint8_t pageSel = PackBits(si, 1, DemodBuffer); si += 1; //uint8_t fastWrite = PackBits(si, 1, DemodBuffer); si += 1; si += 1+1; - int bitRate = PackBits(si, 5, DemodBuffer)*2 + 2; si += 5; //bit rate + int bitRate = PackBits(si, 6, DemodBuffer)*2 + 2; si += 6; //bit rate if (bitRate > 128 || bitRate < 8) continue; //uint8_t AOR = PackBits(si, 1, DemodBuffer); si += 1; @@ -703,7 +711,8 @@ bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk){ //test modulation if (!testQ5Modulation(mode, modread)) continue; if (bitRate != clk) continue; - *fndBitRate = bitRate; + *fndBitRate = convertQ5bitRate(bitRate); + if (*fndBitRate < 0) continue; *offset = idx; return TRUE; @@ -1109,44 +1118,25 @@ int AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password ){ return 1; } -char * GetBitRateStr(uint32_t id){ - static char buf[25]; +char * GetBitRateStr(uint32_t id) { + static char buf[25]; char *retStr = buf; - switch (id){ - case 0: - snprintf(retStr,sizeof(buf),"%d - RF/8",id); - break; - case 1: - snprintf(retStr,sizeof(buf),"%d - RF/16",id); - break; - case 2: - snprintf(retStr,sizeof(buf),"%d - RF/32",id); - break; - case 3: - snprintf(retStr,sizeof(buf),"%d - RF/40",id); - break; - case 4: - snprintf(retStr,sizeof(buf),"%d - RF/50",id); - break; - case 5: - snprintf(retStr,sizeof(buf),"%d - RF/64",id); - break; - case 6: - snprintf(retStr,sizeof(buf),"%d - RF/100",id); - break; - case 7: - snprintf(retStr,sizeof(buf),"%d - RF/128",id); - break; - default: - snprintf(retStr,sizeof(buf),"%d - (Unknown)",id); - break; - } - + switch (id) { + case 0: snprintf(retStr,sizeof(buf),"%d - RF/8",id); break; + case 1: snprintf(retStr,sizeof(buf),"%d - RF/16",id); break; + case 2: snprintf(retStr,sizeof(buf),"%d - RF/32",id); break; + case 3: snprintf(retStr,sizeof(buf),"%d - RF/40",id); break; + case 4: snprintf(retStr,sizeof(buf),"%d - RF/50",id); break; + case 5: snprintf(retStr,sizeof(buf),"%d - RF/64",id); break; + case 6: snprintf(retStr,sizeof(buf),"%d - RF/100",id); break; + case 7: snprintf(retStr,sizeof(buf),"%d - RF/128",id); break; + default: snprintf(retStr,sizeof(buf),"%d - (Unknown)",id); break; + } return buf; } -char * GetSaferStr(uint32_t id){ +char * GetSaferStr(uint32_t id) { static char buf[40]; char *retStr = buf; diff --git a/client/util.c b/client/util.c index e8b72e81..32c06e91 100644 --- a/client/util.c +++ b/client/util.c @@ -142,7 +142,7 @@ char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t brea for (size_t out_index=0; out_index < max_len; out_index++) { // set character sprintf(tmp++, "%u", data[in_index]); - // check if a line break is needed + // check if a line break is needed and we have room to print it in our array if ( (breaks > 0) && !((in_index+1) % breaks) && (out_index+1 != max_len) ) { // increment and print line break out_index++; @@ -271,7 +271,7 @@ char param_getchar(const char *line, int paramnum) uint8_t param_get8(const char *line, int paramnum) { - return param_get8ex(line, paramnum, 10, 0); + return param_get8ex(line, paramnum, 0, 10); } /**