mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
fix: lf sim - dont forget to PACK your structs on both sides\n chg: data convertbitstream - converts bit to max/min in order to facilitate demodulation of simulation data
This commit is contained in:
parent
78d7077f01
commit
f8dbf6138a
8 changed files with 78 additions and 47 deletions
|
@ -1392,7 +1392,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
uint8_t flag;
|
uint8_t flag;
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
};
|
} PACKED;
|
||||||
struct p* payload = (struct p*)packet->data.asBytes;
|
struct p* payload = (struct p*)packet->data.asBytes;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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_OER = GPIO_SSC_DOUT;
|
||||||
AT91C_BASE_PIOA->PIO_ODR = GPIO_SSC_CLK;
|
AT91C_BASE_PIOA->PIO_ODR = GPIO_SSC_CLK;
|
||||||
|
|
||||||
uint8_t check = 1;
|
uint16_t check = 1;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
||||||
|
@ -606,13 +606,16 @@ void SimulateTagLowFrequencyEx(int period, int gap, int ledcontrol, int numcycle
|
||||||
// used as a simple detection of a reader field?
|
// used as a simple detection of a reader field?
|
||||||
while (!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)) {
|
while (!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)) {
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
if (!check) {
|
if ( check == 1000) {
|
||||||
if (usb_poll_validate_length() || BUTTON_PRESS())
|
if (usb_poll_validate_length() || BUTTON_PRESS())
|
||||||
goto OUT;
|
goto OUT;
|
||||||
|
check = 0;
|
||||||
}
|
}
|
||||||
++check;
|
++check;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ledcontrol) LED_D_OFF();
|
||||||
|
|
||||||
if (buf[i])
|
if (buf[i])
|
||||||
OPEN_COIL();
|
OPEN_COIL();
|
||||||
else
|
else
|
||||||
|
@ -621,9 +624,10 @@ void SimulateTagLowFrequencyEx(int period, int gap, int ledcontrol, int numcycle
|
||||||
//wait until SSC_CLK goes LOW
|
//wait until SSC_CLK goes LOW
|
||||||
while (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK) {
|
while (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK) {
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
if (!check) {
|
if (check == 1000) {
|
||||||
if (usb_poll_validate_length() || BUTTON_PRESS())
|
if (usb_poll_validate_length() || BUTTON_PRESS())
|
||||||
goto OUT;
|
goto OUT;
|
||||||
|
check = 0;
|
||||||
}
|
}
|
||||||
++check;
|
++check;
|
||||||
}
|
}
|
||||||
|
@ -636,8 +640,6 @@ void SimulateTagLowFrequencyEx(int period, int gap, int ledcontrol, int numcycle
|
||||||
WaitUS(gap);
|
WaitUS(gap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ledcontrol) LED_D_OFF();
|
|
||||||
}
|
}
|
||||||
OUT:
|
OUT:
|
||||||
StopTicks();
|
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) {
|
void CmdHIDsimTAG(uint32_t hi, uint32_t lo, int ledcontrol) {
|
||||||
CmdHIDsimTAGEx(hi, lo, ledcontrol, -1);
|
CmdHIDsimTAGEx(hi, lo, ledcontrol, -1);
|
||||||
DbpString("[!] simulation finished");
|
|
||||||
reply_ng(CMD_HID_SIM_TAG, PM3_EOPABORTED, NULL, 0);
|
reply_ng(CMD_HID_SIM_TAG, PM3_EOPABORTED, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -446,6 +446,16 @@ int CmdGetBitStream(const char *Cmd) {
|
||||||
RepaintGraphWindow();
|
RepaintGraphWindow();
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
int CmdConvertBitStream(const char *Cmd) {
|
||||||
|
|
||||||
|
if ( isGraphBitstream() ) {
|
||||||
|
convertGraphFromBitstream();
|
||||||
|
} else {
|
||||||
|
// get high, low
|
||||||
|
convertGraphFromBitstreamEx(-126, -127);
|
||||||
|
}
|
||||||
|
return PM3_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
//by marshmellow
|
//by marshmellow
|
||||||
//Cmd Args: Clock, invert, maxErr, maxLen as integers and amplify as char == 'a'
|
//Cmd Args: Clock, invert, maxErr, maxLen as integers and amplify as char == 'a'
|
||||||
|
@ -844,7 +854,9 @@ static int CmdAutoCorr(const char *Cmd) {
|
||||||
//Validations
|
//Validations
|
||||||
if (errors || cmdp == 0) return usage_data_autocorr();
|
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) {
|
static int CmdBitsamples(const char *Cmd) {
|
||||||
|
@ -1481,7 +1493,7 @@ int getSamples(uint32_t n, bool silent) {
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (j = 0; j * bits_per_sample < n * 8 && j < n; j++) {
|
for (j = 0; j * bits_per_sample < n * 8 && j < n; j++) {
|
||||||
uint8_t sample = getByte(bits_per_sample, &bout);
|
uint8_t sample = getByte(bits_per_sample, &bout);
|
||||||
GraphBuffer[j] = ((int) sample) - 128;
|
GraphBuffer[j] = ((int) sample) - 127;
|
||||||
}
|
}
|
||||||
GraphTraceLen = j;
|
GraphTraceLen = j;
|
||||||
|
|
||||||
|
@ -1489,7 +1501,7 @@ int getSamples(uint32_t n, bool silent) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
for (int j = 0; j < n; j++) {
|
for (int j = 0; j < n; j++) {
|
||||||
GraphBuffer[j] = ((int)got[j]) - 128;
|
GraphBuffer[j] = ((int)got[j]) - 127;
|
||||||
}
|
}
|
||||||
GraphTraceLen = n;
|
GraphTraceLen = n;
|
||||||
}
|
}
|
||||||
|
@ -2103,6 +2115,7 @@ static command_t CommandTable[] = {
|
||||||
{"bin2hex", Cmdbin2hex, AlwaysAvailable, "<digits> -- Converts binary to hexadecimal"},
|
{"bin2hex", Cmdbin2hex, AlwaysAvailable, "<digits> -- Converts binary to hexadecimal"},
|
||||||
{"bitsamples", CmdBitsamples, IfPm3Present, "Get raw samples as bitstring"},
|
{"bitsamples", CmdBitsamples, IfPm3Present, "Get raw samples as bitstring"},
|
||||||
{"buffclear", CmdBuffClear, AlwaysAvailable, "Clears bigbuff on deviceside and graph window"},
|
{"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"},
|
{"dec", CmdDec, AlwaysAvailable, "Decimate samples"},
|
||||||
{"detectclock", CmdDetectClockRate, AlwaysAvailable, "[<a|f|n|p>] Detect ASK, FSK, NRZ, PSK clock rate of wave in GraphBuffer"},
|
{"detectclock", CmdDetectClockRate, AlwaysAvailable, "[<a|f|n|p>] 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)"},
|
{"fsktonrz", CmdFSKToNRZ, AlwaysAvailable, "Convert fsk2 to nrz wave for alternate fsk demodulating (for weak fsk)"},
|
||||||
|
|
|
@ -454,15 +454,14 @@ int CmdLFSim(const char *Cmd) {
|
||||||
uint8_t flag;
|
uint8_t flag;
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
uint8_t data[PM3_CMD_DATA_SIZE - 3];
|
uint8_t data[PM3_CMD_DATA_SIZE - 3];
|
||||||
} PACKED;
|
} PACKED payload_up;
|
||||||
struct pupload payload_up;
|
|
||||||
|
|
||||||
// flag =
|
// flag =
|
||||||
// b0 0 upload for LF usage
|
// b0 0 upload for LF usage
|
||||||
// 1 upload for HF usage
|
// 1 upload for HF usage
|
||||||
// b1 0 skip
|
// b1 0 skip
|
||||||
// 1 clear bigbuff
|
// 1 clear bigbuff
|
||||||
payload_up.flag |= 0x2;
|
payload_up.flag = 0x2;
|
||||||
|
|
||||||
// fast push mode
|
// fast push mode
|
||||||
conn.block_after_ACK = true;
|
conn.block_after_ACK = true;
|
||||||
|
@ -477,18 +476,19 @@ int CmdLFSim(const char *Cmd) {
|
||||||
for(uint16_t j = 0; j < len; j++)
|
for(uint16_t j = 0; j < len; j++)
|
||||||
payload_up.data[j] = GraphBuffer[i+j];
|
payload_up.data[j] = GraphBuffer[i+j];
|
||||||
|
|
||||||
|
|
||||||
SendCommandNG(CMD_UPLOAD_SIM_SAMPLES_125K, (uint8_t *)&payload_up, sizeof(struct pupload));
|
SendCommandNG(CMD_UPLOAD_SIM_SAMPLES_125K, (uint8_t *)&payload_up, sizeof(struct pupload));
|
||||||
WaitForResponse(CMD_UPLOAD_SIM_SAMPLES_125K, NULL);
|
WaitForResponse(CMD_UPLOAD_SIM_SAMPLES_125K, NULL);
|
||||||
printf(".");
|
printf(".");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
payload_up.flag = 0;
|
payload_up.flag = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable fast mode before last command
|
// Disable fast mode before last command
|
||||||
conn.block_after_ACK = false;
|
conn.block_after_ACK = false;
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
PrintAndLogEx(INFO, "\nSimulating");
|
PrintAndLogEx(INFO, "Simulating");
|
||||||
|
|
||||||
struct p {
|
struct p {
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
|
|
|
@ -196,7 +196,7 @@ static void ConstructEM410xEmulGraph(const char *uid, const uint8_t clock) {
|
||||||
ClearGraph(true);
|
ClearGraph(true);
|
||||||
|
|
||||||
/* write 16 zero bit sledge */
|
/* write 16 zero bit sledge */
|
||||||
for (i = 0; i < 10; i++)
|
for (i = 0; i < 20; i++)
|
||||||
AppendGraph(false, clock, 0);
|
AppendGraph(false, clock, 0);
|
||||||
|
|
||||||
/* write 9 start bits */
|
/* write 9 start bits */
|
||||||
|
@ -382,33 +382,13 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo) {
|
||||||
|
|
||||||
return PM3_SUCCESS;
|
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) {
|
int AskEm410xDemod(const char *Cmd, uint32_t *hi, uint64_t *lo, bool verbose) {
|
||||||
bool st = true;
|
bool st = true;
|
||||||
|
|
||||||
// em410x simulation etc uses 0/1 as signal data. This must be converted in order to demod it back again
|
// em410x simulation etc uses 0/1 as signal data. This must be converted in order to demod it back again
|
||||||
if ( isBitstream() ) {
|
if ( isGraphBitstream() ) {
|
||||||
for (int i = 0; i < GraphTraceLen; i++) {
|
convertGraphFromBitstream();
|
||||||
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 (ASKDemod_ext(Cmd, false, false, 1, &st) != PM3_SUCCESS)
|
if (ASKDemod_ext(Cmd, false, false, 1, &st) != PM3_SUCCESS)
|
||||||
|
|
|
@ -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
|
//print full HID Prox ID and some bit format details if found
|
||||||
static int CmdHIDDemod(const char *Cmd) {
|
static int CmdHIDDemod(const char *Cmd) {
|
||||||
(void)Cmd; // Cmd is not used so far
|
(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
|
//raw fsk demod no manchester decoding no start bit finding just get binary from wave
|
||||||
uint32_t hi2 = 0, hi = 0, lo = 0;
|
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);
|
size_t size = getFromGraphBuf(bits);
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
PrintAndLogEx(DEBUG, "DEBUG: Error - HID not enough samples");
|
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);
|
SendCommandMIX(CMD_HID_SIM_TAG, hi, lo, 0, NULL, 0);
|
||||||
PacketResponseNG resp;
|
PacketResponseNG resp;
|
||||||
WaitForResponse(CMD_HID_SIM_TAG, &resp);
|
WaitForResponse(CMD_HID_SIM_TAG, &resp);
|
||||||
|
PrintAndLogEx(INFO, "Done");
|
||||||
if (resp.status != PM3_EOPABORTED)
|
if (resp.status != PM3_EOPABORTED)
|
||||||
return resp.status;
|
return resp.status;
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
|
|
|
@ -58,7 +58,6 @@ void save_restoreGB(uint8_t saveOpt) {
|
||||||
GridOffset = SavedGridOffsetAdj;
|
GridOffset = SavedGridOffsetAdj;
|
||||||
RepaintGraphWindow();
|
RepaintGraphWindow();
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setGraphBuf(uint8_t *buff, size_t size) {
|
void setGraphBuf(uint8_t *buff, size_t size) {
|
||||||
|
@ -74,7 +73,6 @@ void setGraphBuf(uint8_t *buff, size_t size) {
|
||||||
|
|
||||||
GraphTraceLen = size;
|
GraphTraceLen = size;
|
||||||
RepaintGraphWindow();
|
RepaintGraphWindow();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getFromGraphBuf(uint8_t *buff) {
|
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.
|
// A simple test to see if there is any data inside Graphbuffer.
|
||||||
bool HasGraphData() {
|
bool HasGraphData(void) {
|
||||||
if (GraphTraceLen == 0) {
|
if (GraphTraceLen == 0) {
|
||||||
PrintAndLogEx(NORMAL, "No data available, try reading something first");
|
PrintAndLogEx(NORMAL, "No data available, try reading something first");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
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
|
// Get or auto-detect ask clock rate
|
||||||
int GetAskClock(const char *str, bool printAns) {
|
int GetAskClock(const char *str, bool printAns) {
|
||||||
|
|
|
@ -20,17 +20,20 @@
|
||||||
|
|
||||||
void AppendGraph(bool redraw, uint16_t clock, int bit);
|
void AppendGraph(bool redraw, uint16_t clock, int bit);
|
||||||
size_t ClearGraph(bool redraw);
|
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);
|
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 GetAskClock(const char *str, bool printAns);
|
||||||
int GetPskClock(const char *str, bool printAns);
|
int GetPskClock(const char *str, bool printAns);
|
||||||
uint8_t GetPskCarrier(const char *str, bool printAns);
|
uint8_t GetPskCarrier(const char *str, bool printAns);
|
||||||
int GetNrzClock(const char *str, bool printAns);
|
int GetNrzClock(const char *str, bool printAns);
|
||||||
int GetFskClock(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);
|
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)
|
// Max graph trace len: 40000 (bigbuf) * 8 (at 1 bit per sample)
|
||||||
#ifndef MAX_GRAPH_TRACE_LEN
|
#ifndef MAX_GRAPH_TRACE_LEN
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue