diff --git a/armsrc/appmain.c b/armsrc/appmain.c index cdd63efe3..a6e136718 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1392,7 +1392,7 @@ static void PacketReceived(PacketCommandNG *packet) { uint8_t flag; uint16_t offset; uint8_t *data; - }; + } PACKED; struct p* payload = (struct p*)packet->data.asBytes; diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 18aeadb07..fbf13f239 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -587,7 +587,7 @@ void SimulateTagLowFrequencyEx(int period, int gap, int ledcontrol, int numcycle AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT; AT91C_BASE_PIOA->PIO_ODR = GPIO_SSC_CLK; - uint8_t check = 1; + uint16_t check = 1; for (;;) { @@ -606,13 +606,16 @@ void SimulateTagLowFrequencyEx(int period, int gap, int ledcontrol, int numcycle // used as a simple detection of a reader field? while (!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)) { WDT_HIT(); - if (!check) { + if ( check == 1000) { if (usb_poll_validate_length() || BUTTON_PRESS()) goto OUT; + check = 0; } ++check; } + if (ledcontrol) LED_D_OFF(); + if (buf[i]) OPEN_COIL(); else @@ -621,9 +624,10 @@ void SimulateTagLowFrequencyEx(int period, int gap, int ledcontrol, int numcycle //wait until SSC_CLK goes LOW while (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK) { WDT_HIT(); - if (!check) { + if (check == 1000) { if (usb_poll_validate_length() || BUTTON_PRESS()) goto OUT; + check = 0; } ++check; } @@ -636,8 +640,6 @@ void SimulateTagLowFrequencyEx(int period, int gap, int ledcontrol, int numcycle WaitUS(gap); } } - - if (ledcontrol) LED_D_OFF(); } OUT: StopTicks(); @@ -818,7 +820,6 @@ void CmdHIDsimTAGEx(uint32_t hi, uint32_t lo, int ledcontrol, int numcycles) { void CmdHIDsimTAG(uint32_t hi, uint32_t lo, int ledcontrol) { CmdHIDsimTAGEx(hi, lo, ledcontrol, -1); - DbpString("[!] simulation finished"); reply_ng(CMD_HID_SIM_TAG, PM3_EOPABORTED, NULL, 0); } diff --git a/client/cmddata.c b/client/cmddata.c index 558cf357d..fb8e2be2f 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -446,6 +446,16 @@ int CmdGetBitStream(const char *Cmd) { RepaintGraphWindow(); return PM3_SUCCESS; } +int CmdConvertBitStream(const char *Cmd) { + + if ( isGraphBitstream() ) { + convertGraphFromBitstream(); + } else { + // get high, low + convertGraphFromBitstreamEx(-126, -127); + } + return PM3_SUCCESS; +} //by marshmellow //Cmd Args: Clock, invert, maxErr, maxLen as integers and amplify as char == 'a' @@ -844,7 +854,9 @@ static int CmdAutoCorr(const char *Cmd) { //Validations if (errors || cmdp == 0) return usage_data_autocorr(); - return AutoCorrelate(GraphBuffer, GraphBuffer, GraphTraceLen, window, updateGrph, true); + AutoCorrelate(GraphBuffer, GraphBuffer, GraphTraceLen, window, updateGrph, true); + + return PM3_SUCCESS; } static int CmdBitsamples(const char *Cmd) { @@ -1481,7 +1493,7 @@ int getSamples(uint32_t n, bool silent) { int j = 0; for (j = 0; j * bits_per_sample < n * 8 && j < n; j++) { uint8_t sample = getByte(bits_per_sample, &bout); - GraphBuffer[j] = ((int) sample) - 128; + GraphBuffer[j] = ((int) sample) - 127; } GraphTraceLen = j; @@ -1489,7 +1501,7 @@ int getSamples(uint32_t n, bool silent) { } else { for (int j = 0; j < n; j++) { - GraphBuffer[j] = ((int)got[j]) - 128; + GraphBuffer[j] = ((int)got[j]) - 127; } GraphTraceLen = n; } @@ -2103,6 +2115,7 @@ static command_t CommandTable[] = { {"bin2hex", Cmdbin2hex, AlwaysAvailable, " -- Converts binary to hexadecimal"}, {"bitsamples", CmdBitsamples, IfPm3Present, "Get raw samples as bitstring"}, {"buffclear", CmdBuffClear, AlwaysAvailable, "Clears bigbuff on deviceside and graph window"}, + {"convertbitstream", CmdConvertBitStream, AlwaysAvailable, "Convert GraphBuffer's 0/1 values to 127 / -127"}, {"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)"}, diff --git a/client/cmdlf.c b/client/cmdlf.c index 7ae06643d..76e26c03e 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -454,15 +454,14 @@ int CmdLFSim(const char *Cmd) { uint8_t flag; uint16_t offset; uint8_t data[PM3_CMD_DATA_SIZE - 3]; - } PACKED; - struct pupload payload_up; + } PACKED payload_up; // flag = // b0 0 upload for LF usage // 1 upload for HF usage // b1 0 skip // 1 clear bigbuff - payload_up.flag |= 0x2; + payload_up.flag = 0x2; // fast push mode conn.block_after_ACK = true; @@ -477,18 +476,19 @@ int CmdLFSim(const char *Cmd) { for(uint16_t j = 0; j < len; j++) payload_up.data[j] = GraphBuffer[i+j]; + SendCommandNG(CMD_UPLOAD_SIM_SAMPLES_125K, (uint8_t *)&payload_up, sizeof(struct pupload)); WaitForResponse(CMD_UPLOAD_SIM_SAMPLES_125K, NULL); printf("."); fflush(stdout); - payload_up.flag = 0; } // Disable fast mode before last command conn.block_after_ACK = false; + printf("\n"); - PrintAndLogEx(INFO, "\nSimulating"); + PrintAndLogEx(INFO, "Simulating"); struct p { uint16_t len; diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c index a3719fa6c..a5e304a86 100644 --- a/client/cmdlfem4x.c +++ b/client/cmdlfem4x.c @@ -196,7 +196,7 @@ static void ConstructEM410xEmulGraph(const char *uid, const uint8_t clock) { ClearGraph(true); /* write 16 zero bit sledge */ - for (i = 0; i < 10; i++) + for (i = 0; i < 20; i++) AppendGraph(false, clock, 0); /* write 9 start bits */ @@ -382,33 +382,13 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo) { return PM3_SUCCESS; } -static bool isBitstream(void) { - // convert to bitstream if necessary - for (int i = 0; i < GraphTraceLen; i++) { - if (GraphBuffer[i] > 1 || GraphBuffer[i] < 0) { - return false; - } - } - return true; -} + int AskEm410xDemod(const char *Cmd, uint32_t *hi, uint64_t *lo, bool verbose) { bool st = true; // em410x simulation etc uses 0/1 as signal data. This must be converted in order to demod it back again - if ( isBitstream() ) { - for (int i = 0; i < GraphTraceLen; i++) { - if (GraphBuffer[i] == 1) - GraphBuffer[i] = 127; - else - GraphBuffer[i] = -127; - } - uint8_t bits[GraphTraceLen]; - memset(bits, 0, sizeof(bits)); - size_t size = getFromGraphBuf(bits); - - // set signal properties low/high/mean/amplitude and is_noise detection - computeSignalProperties(bits, size); - RepaintGraphWindow(); + if ( isGraphBitstream() ) { + convertGraphFromBitstream(); } if (ASKDemod_ext(Cmd, false, false, 1, &st) != PM3_SUCCESS) diff --git a/client/cmdlfhid.c b/client/cmdlfhid.c index 5d0556ade..e8c3fabc1 100644 --- a/client/cmdlfhid.c +++ b/client/cmdlfhid.c @@ -122,10 +122,16 @@ static int sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, uin //print full HID Prox ID and some bit format details if found static int CmdHIDDemod(const char *Cmd) { (void)Cmd; // Cmd is not used so far + + // HID simulation etc uses 0/1 as signal data. This must be converted in order to demod it back again + if ( isGraphBitstream() ) { + convertGraphFromBitstream(); + } + //raw fsk demod no manchester decoding no start bit finding just get binary from wave uint32_t hi2 = 0, hi = 0, lo = 0; - uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0}; + uint8_t bits[GraphTraceLen]; size_t size = getFromGraphBuf(bits); if (size == 0) { PrintAndLogEx(DEBUG, "DEBUG: Error - HID not enough samples"); @@ -261,6 +267,7 @@ static int CmdHIDSim(const char *Cmd) { SendCommandMIX(CMD_HID_SIM_TAG, hi, lo, 0, NULL, 0); PacketResponseNG resp; WaitForResponse(CMD_HID_SIM_TAG, &resp); + PrintAndLogEx(INFO, "Done"); if (resp.status != PM3_EOPABORTED) return resp.status; return PM3_SUCCESS; diff --git a/client/graph.c b/client/graph.c index 363dd0d61..c70d6f434 100644 --- a/client/graph.c +++ b/client/graph.c @@ -58,7 +58,6 @@ void save_restoreGB(uint8_t saveOpt) { GridOffset = SavedGridOffsetAdj; RepaintGraphWindow(); } - return; } void setGraphBuf(uint8_t *buff, size_t size) { @@ -74,7 +73,6 @@ void setGraphBuf(uint8_t *buff, size_t size) { GraphTraceLen = size; RepaintGraphWindow(); - return; } size_t getFromGraphBuf(uint8_t *buff) { @@ -90,13 +88,42 @@ size_t getFromGraphBuf(uint8_t *buff) { } // A simple test to see if there is any data inside Graphbuffer. -bool HasGraphData() { +bool HasGraphData(void) { if (GraphTraceLen == 0) { PrintAndLogEx(NORMAL, "No data available, try reading something first"); return false; } return true; } +bool isGraphBitstream(void) { + // convert to bitstream if necessary + for (int i = 0; i < GraphTraceLen; i++) { + if (GraphBuffer[i] > 1 || GraphBuffer[i] < 0) { + return false; + } + } + return true; +} +void convertGraphFromBitstream() { + convertGraphFromBitstreamEx(1, 0); +} +void convertGraphFromBitstreamEx(int hi, int low) { + for (int i = 0; i < GraphTraceLen; i++) { + if (GraphBuffer[i] == hi) + GraphBuffer[i] = 127; + else if ( GraphBuffer[i] == low ) + GraphBuffer[i] = -127; + else + GraphBuffer[i] = 0; + } + uint8_t bits[GraphTraceLen]; + memset(bits, 0, sizeof(bits)); + size_t size = getFromGraphBuf(bits); + + // set signal properties low/high/mean/amplitude and is_noise detection + computeSignalProperties(bits, size); + RepaintGraphWindow(); +} // Get or auto-detect ask clock rate int GetAskClock(const char *str, bool printAns) { diff --git a/client/graph.h b/client/graph.h index 2733bf475..fca93a889 100644 --- a/client/graph.h +++ b/client/graph.h @@ -20,17 +20,20 @@ void AppendGraph(bool redraw, uint16_t clock, int bit); size_t ClearGraph(bool redraw); +bool HasGraphData(void); +void setGraphBuf(uint8_t *buff, size_t size); +void save_restoreGB(uint8_t saveOpt); size_t getFromGraphBuf(uint8_t *buff); +void convertGraphFromBitstream(void); +void convertGraphFromBitstreamEx(int hi, int low); +bool isGraphBitstream(void); + int GetAskClock(const char *str, bool printAns); int GetPskClock(const char *str, bool printAns); uint8_t GetPskCarrier(const char *str, bool printAns); int GetNrzClock(const char *str, bool printAns); int GetFskClock(const char *str, bool printAns); bool fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, int *firstClockEdge); -void setGraphBuf(uint8_t *buff, size_t size); -void save_restoreGB(uint8_t saveOpt); - -bool HasGraphData(void); // Max graph trace len: 40000 (bigbuf) * 8 (at 1 bit per sample) #ifndef MAX_GRAPH_TRACE_LEN