X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/c15d2bdc9b25da89931c767902639fa7e8c9b764..0452ec6c906c2389c761c1dd6b0a4b5f67defe32:/client/cmdlfem4x.c diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c index 07f909ac..a0cd87ca 100644 --- a/client/cmdlfem4x.c +++ b/client/cmdlfem4x.c @@ -28,6 +28,16 @@ char *global_em410xId; static int CmdHelp(const char *Cmd); +int CmdEMdemodASK(const char *Cmd) +{ + char cmdp = param_getchar(Cmd, 0); + int findone = (cmdp == '1') ? 1 : 0; + UsbCommand c = { CMD_EM410X_DEMOD }; + c.arg[0] = findone; + SendCommand(&c); + return 0; +} + /* Read the ID of an EM410x tag. * Format: * 1111 1111 1 <-- standard non-repeatable header @@ -40,29 +50,25 @@ int CmdEM410xRead(const char *Cmd) { int i, j, clock, header, rows, bit, hithigh, hitlow, first, bit2idx, high, low; int parity[4]; - char id[11]; - char id2[11]; + char id[11] = {0x00}; + char id2[11] = {0x00}; int retested = 0; uint8_t BitStream[MAX_GRAPH_TRACE_LEN]; high = low = 0; - /* Detect high and lows and clock */ - for (i = 0; i < GraphTraceLen; i++) - { - if (GraphBuffer[i] > high) - high = GraphBuffer[i]; - else if (GraphBuffer[i] < low) - low = GraphBuffer[i]; - } + // get clock + clock = GetClock(Cmd, 0); + + // Detect high and lows and clock + DetectHighLowInGraph( &high, &low, TRUE); - /* get clock */ - clock = GetClock(Cmd, high, 0); - - /* parity for our 4 columns */ + PrintAndLog("NUMNUM"); + + // parity for our 4 columns parity[0] = parity[1] = parity[2] = parity[3] = 0; header = rows = 0; - /* manchester demodulate */ + // manchester demodulate bit = bit2idx = 0; for (i = 0; i < (int)(GraphTraceLen / clock); i++) { @@ -73,9 +79,9 @@ int CmdEM410xRead(const char *Cmd) /* Find out if we hit both high and low peaks */ for (j = 0; j < clock; j++) { - if (GraphBuffer[(i * clock) + j] == high) + if (GraphBuffer[(i * clock) + j] >= high) hithigh = 1; - else if (GraphBuffer[(i * clock) + j] == low) + else if (GraphBuffer[(i * clock) + j] <= low) hitlow = 1; /* it doesn't count if it's the first part of our read @@ -95,7 +101,7 @@ int CmdEM410xRead(const char *Cmd) BitStream[bit2idx++] = bit; } - + retest: /* We go till 5 before the graph ends because we'll get that far below */ for (i = 0; i < bit2idx - 5; i++) @@ -175,13 +181,14 @@ retest: } /* if we've already retested after flipping bits, return */ - if (retested++){ - return 0; + if (retested++){ + PrintAndLog("Failed to decode"); + return 0; } /* if this didn't work, try flipping bits */ - for (i = 0; i < bit2idx; i++) - BitStream[i] ^= 1; + for (i = 0; i < bit2idx; i++) + BitStream[i] ^= 1; goto retest; } @@ -196,15 +203,15 @@ retest: */ int CmdEM410xSim(const char *Cmd) { - int i, n, j, h, binary[4], parity[4]; + int i, n, j, binary[4], parity[4]; char cmdp = param_getchar(Cmd, 0); uint8_t uid[5] = {0x00}; if (cmdp == 'h' || cmdp == 'H') { - PrintAndLog("Usage: lf em4x sim "); + PrintAndLog("Usage: lf em4x 410xsim "); PrintAndLog(""); - PrintAndLog(" sample: lf em4x sim 0F0368568B"); + PrintAndLog(" sample: lf em4x 410xsim 0F0368568B"); return 0; } @@ -222,9 +229,6 @@ int CmdEM410xSim(const char *Cmd) /* clear our graph */ ClearGraph(0); - /* write it out a few times */ - //for (h = 0; h < 4; h++) - //{ /* write 9 start bits */ for (i = 0; i < 9; i++) AppendGraph(0, clock, 1); @@ -260,17 +264,10 @@ int CmdEM410xSim(const char *Cmd) AppendGraph(0, clock, parity[2]); AppendGraph(0, clock, parity[3]); - /* stop bit */ - AppendGraph(0, clock, 0); - //} - - /* modulate that biatch */ - //CmdManchesterMod("64"); - - /* booyah! */ - RepaintGraphWindow(); - - CmdLFSim(""); + /* stop bit */ + AppendGraph(1, clock, 0); + + CmdLFSim("240"); //240 start_gap. return 0; } @@ -286,7 +283,8 @@ int CmdEM410xSim(const char *Cmd) */ int CmdEM410xWatch(const char *Cmd) { - int read_h = (*Cmd == 'h'); + char cmdp = param_getchar(Cmd, 0); + int read_h = (cmdp == 'h'); do { if (ukbhit()) { @@ -547,7 +545,7 @@ int CmdReadWord(const char *Cmd) uint8_t data[LF_TRACE_BUFF_SIZE] = {0x00}; - GetFromBigBuf(data,LF_TRACE_BUFF_SIZE,3560); //3560 -- should be offset.. + GetFromBigBuf(data,LF_TRACE_BUFF_SIZE,0); //3560 -- should be offset.. WaitForResponseTimeout(CMD_ACK,NULL, 1500); for (int j = 0; j < LF_TRACE_BUFF_SIZE; j++) { @@ -587,7 +585,7 @@ int CmdReadWordPWD(const char *Cmd) uint8_t data[LF_TRACE_BUFF_SIZE] = {0x00}; - GetFromBigBuf(data,LF_TRACE_BUFF_SIZE,3560); //3560 -- should be offset.. + GetFromBigBuf(data,LF_TRACE_BUFF_SIZE,0); //3560 -- should be offset.. WaitForResponseTimeout(CMD_ACK,NULL, 1500); for (int j = 0; j < LF_TRACE_BUFF_SIZE; j++) { @@ -654,7 +652,7 @@ int CmdWriteWordPWD(const char *Cmd) static command_t CommandTable[] = { {"help", CmdHelp, 1, "This help"}, - + {"410xdemod", CmdEMdemodASK, 0, "[clock rate] -- Extract ID from EM410x tag"}, {"410xread", CmdEM410xRead, 1, "[clock rate] -- Extract ID from EM410x tag"}, {"410xsim", CmdEM410xSim, 0, " -- Simulate EM410x tag"}, {"replay", MWRem4xReplay, 0, "Watches for tag and simulates manchester encoded em4x tag"},