X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/5249ff940f17a0ae619c178ea8648c112106e9ae..1f42ccddfb11c6a862c6cb058af765acae038e4d:/client/cmdlfem4x.c diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c index 47b240c8..e84cccf9 100644 --- a/client/cmdlfem4x.c +++ b/client/cmdlfem4x.c @@ -146,17 +146,20 @@ void printEM410x(uint32_t hi, uint64_t id) int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) { size_t idx = 0; - size_t BitLen = DemodBufferLen; - uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0}; - memcpy(BitStream, DemodBuffer, BitLen); - if (Em410xDecode(BitStream, &BitLen, &idx, hi, lo)){ + uint8_t BitStream[512]={0}; + size_t BitLen = sizeof(BitStream); + if ( !getDemodBuf(BitStream, &BitLen) ) return 0; + + if (Em410xDecode(BitStream, &BitLen, &idx, hi, lo)) { //set GraphBuffer for clone or sim command - setDemodBuf(BitStream, BitLen, idx); - if (g_debugMode){ + setDemodBuf(DemodBuffer, (BitLen==40) ? 64 : 128, idx+1); + setClockGrid(g_DemodClock, g_DemodStartIdx + ((idx+1)*g_DemodClock)); + + if (g_debugMode) { PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, BitLen); printDemodBuff(); } - if (verbose){ + if (verbose) { PrintAndLog("EM410x pattern found: "); printEM410x(*hi, *lo); g_em410xId = *lo; @@ -298,9 +301,7 @@ int CmdEM410xWatch(const char *Cmd) printf("\naborted via keyboard!\n"); break; } - - CmdLFRead("s"); - getSamples("8201",true); + lf_read(true, 8201); } while (!CmdAskEM410xDemod("")); return 0; @@ -473,9 +474,6 @@ int EM4x50Read(const char *Cmd, bool verbose) // get user entry if any sscanf(Cmd, "%i %i", &clk, &invert); - // save GraphBuffer - to restore it later - save_restoreGB(1); - // first get high and low values for (i = 0; i < GraphTraceLen; i++) { if (GraphBuffer[i] > high) @@ -572,6 +570,8 @@ int EM4x50Read(const char *Cmd, bool verbose) } else if (start < 0) return 0; start = skip; snprintf(tmp2, sizeof(tmp2),"%d %d 1000 %d", clk, invert, clk*47); + // save GraphBuffer - to restore it later + save_restoreGB(GRAPH_SAVE); // get rid of leading crap snprintf(tmp, sizeof(tmp), "%i", skip); CmdLtrim(tmp); @@ -599,7 +599,7 @@ int EM4x50Read(const char *Cmd, bool verbose) phaseoff = 0; i += 2; if (ASKDemod(tmp2, false, false, 1) < 1) { - save_restoreGB(0); + save_restoreGB(GRAPH_RESTORE); return 0; } //set DemodBufferLen to just one block @@ -638,7 +638,7 @@ int EM4x50Read(const char *Cmd, bool verbose) } //restore GraphBuffer - save_restoreGB(0); + save_restoreGB(GRAPH_RESTORE); return (int)AllPTest; } @@ -704,6 +704,8 @@ bool EM4x05testDemodReadData(uint32_t *word, bool readCmd) { } setDemodBuf(DemodBuffer, 32, 0); + //setClockGrid(0,0); + *word = bytebits_to_byteLSBF(DemodBuffer, 32); } return true; @@ -914,6 +916,9 @@ int usage_lf_em_write(void) { return 0; } +// note: em4x05 doesn't have a way to invert data output so we must invert the data prior to writing +// it if invertion is needed. (example FSK2a vs FSK) +// also em4x05 requires swapping word data when compared to the data used for t55xx chips. int EM4x05WriteWord(uint8_t addr, uint32_t data, uint32_t pwd, bool usePwd, bool swap, bool invert) { if (swap) data = SwapBits(data, 32); @@ -921,7 +926,7 @@ int EM4x05WriteWord(uint8_t addr, uint32_t data, uint32_t pwd, bool usePwd, bool if ( (addr > 15) ) { PrintAndLog("Address must be between 0 and 15"); - return 1; + return -1; } if ( !usePwd ) { PrintAndLog("Writing address %d data %08X", addr, data); @@ -962,7 +967,7 @@ int CmdEM4x05WriteWord(const char *Cmd) { bool swap = false; bool invert = false; uint8_t addr = 16; // default to invalid address - + bool gotData = false; char cmdp = 0; while(param_getchar(Cmd, cmdp) != 0x00) { @@ -979,6 +984,7 @@ int CmdEM4x05WriteWord(const char *Cmd) { case 'd': case 'D': data = param_get32ex(Cmd, cmdp+1, 0, 16); + gotData = true; cmdp += 2; break; case 'i': @@ -1013,6 +1019,10 @@ int CmdEM4x05WriteWord(const char *Cmd) { if ( strlen(Cmd) == 0 ) return usage_lf_em_write(); + if (!gotData) { + PrintAndLog("You must enter the data you want to write"); + return usage_lf_em_write(); + } return EM4x05WriteWord(addr, data, pwd, usePwd, swap, invert); }