adjust LFSim to download lf fpga prior to setting emulation buffer

to prevent buffer overwrite condition if you are coming from HF fpga.
This commit is contained in:
marshmellow42 2017-09-11 12:38:01 -04:00
commit e8defa30f7
2 changed files with 11 additions and 7 deletions

View file

@ -410,28 +410,32 @@ int CmdLFSim(const char *Cmd)
sscanf(Cmd, "%i", &gap); sscanf(Cmd, "%i", &gap);
// convert to bitstream if necessary //prep fpga to lf (divisor is not important)
UsbCommand c = {CMD_SET_LF_DIVISOR, {89,0,0}};
clearCommandBuffer();
SendCommand(&c);
// convert to bitstream if necessary
ChkBitstream(Cmd); ChkBitstream(Cmd);
//can send only 512 bits at a time (1 byte sent per bit...) //can send only 512 bits at a time (1 byte sent per bit...)
printf("Sending [%d bytes]", GraphTraceLen); printf("Sending [%d bytes]", GraphTraceLen);
for (i = 0; i < GraphTraceLen; i += USB_CMD_DATA_SIZE) { for (i = 0; i < GraphTraceLen; i += USB_CMD_DATA_SIZE) {
UsbCommand c={CMD_DOWNLOADED_SIM_SAMPLES_125K, {i, 0, 0}}; UsbCommand c2 = {CMD_DOWNLOADED_SIM_SAMPLES_125K, {i, 0, 0}};
for (j = 0; j < USB_CMD_DATA_SIZE; j++) { for (j = 0; j < USB_CMD_DATA_SIZE; j++) {
c.d.asBytes[j] = GraphBuffer[i+j]; c2.d.asBytes[j] = GraphBuffer[i+j];
} }
SendCommand(&c); SendCommand(&c2);
WaitForResponse(CMD_ACK,NULL); WaitForResponse(CMD_ACK,NULL);
printf("."); printf(".");
} }
printf("\n"); printf("\n");
PrintAndLog("Starting to simulate"); PrintAndLog("Starting to simulate");
UsbCommand c = {CMD_SIMULATE_TAG_125K, {GraphTraceLen, gap, 0}}; UsbCommand c3 = {CMD_SIMULATE_TAG_125K, {GraphTraceLen, gap, 0}};
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c3);
return 0; return 0;
} }