// Jonathan Westhues, Sept 2005\r
// Edits by Gerhard de Koning Gans, Sep 2007 (##)\r
//-----------------------------------------------------------------------------\r
-#ifdef _WIN32\r
+#ifdef WIN32\r
#include <windows.h>\r
#endif\r
+#include <unistd.h>\r
#include <stdlib.h>\r
#include <string.h>\r
#include <stdio.h>\r
#include <limits.h>\r
#include <math.h>\r
-#ifdef _MSC_VER\r
-typedef DWORD uint32_t;\r
-typedef BYTE uint8_t;\r
-typedef WORD uint16_t;\r
-#define bool BOOL\r
-#define true TRUE\r
-#define false FALSE\r
-#else\r
-#include <stdint.h>\r
-#include <stdbool.h>\r
-#endif\r
\r
#include "prox.h"\r
#include "../common/iso14443_crc.c"\r
#include "../common/crc16.c"\r
+#include "../include/usb_cmd.h"\r
\r
#define arraylen(x) (sizeof(x)/sizeof((x)[0]))\r
#define BIT(x) GraphBuffer[x * clock]\r
#define BITS (GraphTraceLen / clock)\r
+#define SAMPLE_BUFFER_SIZE 64 // XXX check this\r
\r
int go = 0;\r
static int CmdHisamplest(char *str, int nrlow);\r
+unsigned int current_command = CMD_UNKNOWN;\r
+unsigned int received_command = CMD_UNKNOWN;\r
+static uint8_t sample_buf[SAMPLE_BUFFER_SIZE];\r
+\r
+void wait_for_response(uint32_t response_type)\r
+{\r
+ while (received_command != response_type) {\r
+#ifdef WIN32\r
+ UsbCommand c;\r
+ if (ReceiveCommandPoll(&c))\r
+ UsbCommandReceived(&c);\r
+ Sleep(0);\r
+#else\r
+ usleep(10000); // XXX ugh\r
+#endif\r
+ }\r
+ received_command = CMD_UNKNOWN;\r
+}\r
\r
static void GetFromBigBuf(uint8_t *dest, int bytes)\r
{\r
int n = bytes/4;\r
- int i;\r
\r
if(n % 48 != 0) {\r
PrintToScrollback("bad len in GetFromBigBuf");\r
return;\r
}\r
\r
+ int i;\r
for(i = 0; i < n; i += 12) {\r
- UsbCommand c;\r
- c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K;\r
- c.arg[0] = i;\r
- SendCommand(&c, false);\r
- ReceiveCommand(&c);\r
- if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) {\r
- PrintToScrollback("bad resp");\r
- return;\r
- }\r
+ UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};\r
+ SendCommand(&c);\r
+ wait_for_response(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);\r
\r
- memcpy(dest+(i*4), c.d.asBytes, 48);\r
+ memcpy(dest+(i*4), sample_buf, 48);\r
}\r
}\r
\r
static void CmdReset(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_HARDWARE_RESET;\r
- SendCommand(&c, false);\r
+ UsbCommand c = {CMD_HARDWARE_RESET};\r
+ SendCommand(&c);\r
}\r
\r
static void CmdBuffClear(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_BUFF_CLEAR;\r
- SendCommand(&c, false);\r
+ UsbCommand c = {CMD_BUFF_CLEAR};\r
+ SendCommand(&c);\r
CmdClearGraph(true);\r
}\r
\r
\r
static void CmdHIDdemodFSK(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_HID_DEMOD_FSK;\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_HID_DEMOD_FSK};\r
+ SendCommand(&c);\r
}\r
\r
static void CmdTune(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_MEASURE_ANTENNA_TUNING;\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_MEASURE_ANTENNA_TUNING};\r
+ SendCommand(&c);\r
}\r
\r
static void CmdHi15read(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_15693;\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_15693};\r
+ SendCommand(&c);\r
}\r
\r
static void CmdHi14read(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443;\r
- c.arg[0] = atoi(str);\r
- SendCommand(&c, false);\r
+ UsbCommand c = {CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443, {strtol(str, NULL, 0), 0, 0}};\r
+ SendCommand(&c);\r
}\r
\r
\r
/* New command to read the contents of a SRI512 tag\r
* SRI512 tags are ISO14443-B modulated memory tags,\r
- * this command just dumps the contents of the memory/\r
+ * this command just dumps the contents of the memory\r
*/\r
static void CmdSri512read(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_READ_SRI512_TAG;\r
- c.arg[0] = atoi(str);\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_READ_SRI512_TAG, {strtol(str, NULL, 0), 0, 0}};\r
+ SendCommand(&c);\r
}\r
\r
/* New command to read the contents of a SRIX4K tag\r
*/\r
static void CmdSrix4kread(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_READ_SRIX4K_TAG;\r
- c.arg[0] = atoi(str);\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_READ_SRIX4K_TAG, {strtol(str, NULL, 0), 0, 0}};\r
+ SendCommand(&c);\r
}\r
\r
-\r
-\r
-// ## New command\r
static void CmdHi14areader(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_READER_ISO_14443a;\r
- c.arg[0] = atoi(str);\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_READER_ISO_14443a, {strtol(str, NULL, 0), 0, 0}};\r
+ SendCommand(&c);\r
+}\r
+\r
+static void CmdHi14amifare(char *str)\r
+{\r
+ UsbCommand c={CMD_READER_MIFARE, {strtol(str, NULL, 0), 0, 0}};\r
+ SendCommand(&c);\r
}\r
\r
-// ## New command\r
static void CmdHi15reader(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_READER_ISO_15693;\r
- c.arg[0] = atoi(str);\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_READER_ISO_15693, {strtol(str, NULL, 0), 0, 0}};\r
+ SendCommand(&c);\r
}\r
\r
-// ## New command\r
static void CmdHi15tag(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_SIMTAG_ISO_15693;\r
- c.arg[0] = atoi(str);\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_SIMTAG_ISO_15693, {strtol(str, NULL, 0), 0, 0}};\r
+ SendCommand(&c);\r
}\r
\r
static void CmdHi14read_sim(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM;\r
- c.arg[0] = atoi(str);\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM, {strtol(str, NULL, 0), 0, 0}};\r
+ SendCommand(&c);\r
}\r
\r
static void CmdHi14readt(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443;\r
- c.arg[0] = atoi(str);\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443, {strtol(str, NULL, 0), 0, 0}};\r
+ SendCommand(&c);\r
\r
//CmdHisamplest(str);\r
- while(CmdHisamplest(str,atoi(str))==0) {\r
- c.cmd = CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443;\r
- c.arg[0] = atoi(str);\r
- SendCommand(&c, false);\r
+ while(CmdHisamplest(str,strtol(str, NULL, 0))==0) {\r
+ SendCommand(&c);\r
}\r
RepaintGraphWindow();\r
}\r
\r
static void CmdHisimlisten(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_SIMULATE_TAG_HF_LISTEN;\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_SIMULATE_TAG_HF_LISTEN};\r
+ SendCommand(&c);\r
}\r
\r
static void CmdHi14sim(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_SIMULATE_TAG_ISO_14443;\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_SIMULATE_TAG_ISO_14443};\r
+ SendCommand(&c);\r
}\r
\r
static void CmdHi14asim(char *str) // ## simulate iso14443a tag\r
\r
unsigned int hi=0, lo=0;\r
int n=0, i=0;\r
- UsbCommand c;\r
-\r
while (sscanf(&str[i++], "%1x", &n ) == 1) {\r
hi=(hi<<4)|(lo>>28);\r
lo=(lo<<4)|(n&0xf);\r
}\r
\r
- c.cmd = CMD_SIMULATE_TAG_ISO_14443a;\r
- // c.ext should be set to *str or convert *str to the correct format for a uid\r
- c.arg[0] = hi;\r
- c.arg[1] = lo;\r
+ // c.arg should be set to *str or convert *str to the correct format for a uid\r
+ UsbCommand c = {CMD_SIMULATE_TAG_ISO_14443a, {hi, lo, 0}};\r
PrintToScrollback("Emulating 14443A TAG with UID %x%16x", hi, lo);\r
- SendCommand(&c, false);\r
+ SendCommand(&c);\r
}\r
\r
static void CmdHi14snoop(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_SNOOP_ISO_14443;\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_SNOOP_ISO_14443};\r
+ SendCommand(&c);\r
}\r
\r
static void CmdHi14asnoop(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_SNOOP_ISO_14443a;\r
- SendCommand(&c, false);\r
-}\r
-\r
-static void CmdLegicRfSim(char *str)\r
-{\r
- UsbCommand c;\r
- c.cmd = CMD_SIMULATE_TAG_LEGIC_RF;\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_SNOOP_ISO_14443a};\r
+ SendCommand(&c);\r
}\r
\r
static void CmdLegicRfRead(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_READER_LEGIC_RF;\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_READER_LEGIC_RF};\r
+ SendCommand(&c);\r
}\r
\r
static void CmdFPGAOff(char *str) // ## FPGA Control\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_FPGA_MAJOR_MODE_OFF;\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_FPGA_MAJOR_MODE_OFF};\r
+ SendCommand(&c);\r
}\r
\r
/* clear out our graph window */\r
static void CmdLosim(char *str)\r
{\r
int i;\r
- UsbCommand c;\r
\r
/* convert to bitstream if necessary */\r
ChkBitstream(str);\r
\r
for (i = 0; i < GraphTraceLen; i += 48) {\r
- UsbCommand c;\r
+ UsbCommand c={CMD_DOWNLOADED_SIM_SAMPLES_125K, {i, 0, 0}};\r
int j;\r
for(j = 0; j < 48; j++) {\r
c.d.asBytes[j] = GraphBuffer[i+j];\r
}\r
- c.cmd = CMD_DOWNLOADED_SIM_SAMPLES_125K;\r
- c.arg[0] = i;\r
- SendCommand(&c, false);\r
+ SendCommand(&c);\r
}\r
\r
- c.cmd = CMD_SIMULATE_TAG_125K;\r
- c.arg[0] = GraphTraceLen;\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_SIMULATE_TAG_125K, {GraphTraceLen, 0, 0}};\r
+ SendCommand(&c);\r
}\r
\r
static void CmdLosimBidir(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_LF_SIMULATE_BIDIR;\r
- c.arg[0] = 47; /* Set ADC to twice the carrier for a slight supersampling */\r
- c.arg[1] = 384;\r
- SendCommand(&c, false);\r
+ /* Set ADC to twice the carrier for a slight supersampling */\r
+ UsbCommand c={CMD_LF_SIMULATE_BIDIR, {47, 384, 0}};\r
+ SendCommand(&c);\r
}\r
\r
static void CmdLoread(char *str)\r
{\r
- UsbCommand c;\r
+ UsbCommand c={CMD_ACQUIRE_RAW_ADC_SAMPLES_125K};\r
// 'h' means higher-low-frequency, 134 kHz\r
if(*str == 'h') {\r
c.arg[0] = 1;\r
PrintToScrollback("use 'loread' or 'loread h'");\r
return;\r
}\r
- c.cmd = CMD_ACQUIRE_RAW_ADC_SAMPLES_125K;\r
- SendCommand(&c, false);\r
+ SendCommand(&c);\r
}\r
\r
static void CmdDetectReader(char *str)\r
{\r
- UsbCommand c;\r
+ UsbCommand c={CMD_LISTEN_READER_FIELD};\r
// 'l' means LF - 125/134 kHz\r
if(*str == 'l') {\r
c.arg[0] = 1;\r
PrintToScrollback("use 'detectreader' or 'detectreader l' or 'detectreader h'");\r
return;\r
}\r
- c.cmd = CMD_LISTEN_READER_FIELD;\r
- SendCommand(&c, false);\r
+ SendCommand(&c);\r
}\r
\r
/* send a command before reading */\r
static void CmdLoCommandRead(char *str)\r
{\r
static char dummy[3];\r
- UsbCommand c;\r
\r
dummy[0]= ' ';\r
\r
- c.cmd = CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K;\r
+ UsbCommand c={CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K};\r
sscanf(str, "%i %i %i %s %s", &c.arg[0], &c.arg[1], &c.arg[2], (char *) &c.d.asBytes,(char *) &dummy+1);\r
// in case they specified 'h'\r
strcpy((char *)&c.d.asBytes + strlen((char *)c.d.asBytes), dummy);\r
- SendCommand(&c, false);\r
+ SendCommand(&c);\r
}\r
\r
static void CmdLosamples(char *str)\r
{\r
int cnt = 0;\r
- int i;\r
- int n;\r
- int j;\r
+ int i, j, n;\r
\r
- n=atoi(str);\r
+ n=strtol(str, NULL, 0);\r
if (n==0) n=128;\r
if (n>16000) n=16000;\r
\r
+ PrintToScrollback("Reading %d samples\n", n);\r
for(i = 0; i < n; i += 12) {\r
- UsbCommand c;\r
- c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K;\r
- c.arg[0] = i;\r
- SendCommand(&c, false);\r
- ReceiveCommand(&c);\r
- if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) {\r
- if (!go)\r
- PrintToScrollback("bad resp");\r
- return;\r
- }\r
+ UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};\r
+ SendCommand(&c);\r
+ wait_for_response(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);\r
for(j = 0; j < 48; j++) {\r
- GraphBuffer[cnt++] = ((int)c.d.asBytes[j]) - 128;\r
+ GraphBuffer[cnt++] = ((int)sample_buf[j]) - 128;\r
}\r
}\r
+ PrintToScrollback("Done!\n");\r
GraphTraceLen = n*4;\r
RepaintGraphWindow();\r
}\r
static void CmdBitsamples(char *str)\r
{\r
int cnt = 0;\r
- int i;\r
- int n;\r
- int j, k;\r
+ int i, j, k, n;\r
\r
n = 3072;\r
for(i = 0; i < n; i += 12) {\r
- UsbCommand c;\r
- c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K;\r
- c.arg[0] = i;\r
- SendCommand(&c, false);\r
- ReceiveCommand(&c);\r
- if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) {\r
- PrintToScrollback("bad resp");\r
- return;\r
- }\r
+ UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};\r
+ SendCommand(&c);\r
+ wait_for_response(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);\r
+\r
for(j = 0; j < 48; j++) {\r
for(k = 0; k < 8; k++) {\r
- if(c.d.asBytes[j] & (1 << (7 - k))) {\r
+ if(sample_buf[j] & (1 << (7 - k))) {\r
GraphBuffer[cnt++] = 1;\r
} else {\r
GraphBuffer[cnt++] = 0;\r
static void CmdHisamples(char *str)\r
{\r
int cnt = 0;\r
- int i;\r
- int n;\r
- int j;\r
+ int i, j, n;\r
+\r
n = 1000;\r
for(i = 0; i < n; i += 12) {\r
- UsbCommand c;\r
- c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K;\r
- c.arg[0] = i;\r
- SendCommand(&c, false);\r
- ReceiveCommand(&c);\r
- if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) {\r
- PrintToScrollback("bad resp");\r
- return;\r
- }\r
+ UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};\r
+ SendCommand(&c);\r
+ wait_for_response(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);\r
for(j = 0; j < 48; j++) {\r
- GraphBuffer[cnt++] = (int)((uint8_t)c.d.asBytes[j]);\r
+ GraphBuffer[cnt++] = (int)(sample_buf[j]);\r
}\r
}\r
- GraphTraceLen = n*4;\r
\r
+ GraphTraceLen = n*4;\r
RepaintGraphWindow();\r
}\r
\r
{\r
int cnt = 0;\r
int t1, t2;\r
- int i;\r
- int n;\r
+ int i, j, n;\r
int hasbeennull;\r
int show;\r
- int j;\r
-\r
\r
n = 1000;\r
hasbeennull = 0;\r
for(i = 0; i < n; i += 12) {\r
- UsbCommand c;\r
- c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K;\r
- c.arg[0] = i;\r
- SendCommand(&c, false);\r
- ReceiveCommand(&c);\r
- if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) {\r
- PrintToScrollback("bad resp");\r
- return 0;\r
- }\r
+ UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};\r
+ SendCommand(&c);\r
+ wait_for_response(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);\r
for(j = 0; j < 48; j++) {\r
- t2 = (int)((uint8_t)c.d.asBytes[j]);\r
+ t2 = (int)(sample_buf[j]);\r
if((t2 ^ 0xC0) & 0xC0) { hasbeennull++; }\r
\r
show = 0;\r
\r
static void CmdHexsamples(char *str)\r
{\r
- int i;\r
- int n;\r
- int requested = atoi(str);\r
+ int i, j, n;\r
+ int requested = strtol(str, NULL, 0);\r
int delivered = 0;\r
- int j;\r
\r
- if(atoi(str) == 0) {\r
+ if (requested == 0) {\r
n = 12;\r
requested = 12;\r
} else {\r
- n = atoi(str)/4;\r
+ n = requested/4;\r
}\r
\r
for(i = 0; i < n; i += 12) {\r
- UsbCommand c;\r
- c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K;\r
- c.arg[0] = i;\r
- SendCommand(&c, false);\r
- ReceiveCommand(&c);\r
- if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) {\r
- PrintToScrollback("bad resp");\r
- return;\r
- }\r
- for(j = 0; j < 48; j += 8) {\r
+ UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};\r
+ SendCommand(&c);\r
+ wait_for_response(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);\r
+ for (j = 0; j < 48; j += 8) {\r
PrintToScrollback("%02x %02x %02x %02x %02x %02x %02x %02x",\r
- c.d.asBytes[j+0],\r
- c.d.asBytes[j+1],\r
- c.d.asBytes[j+2],\r
- c.d.asBytes[j+3],\r
- c.d.asBytes[j+4],\r
- c.d.asBytes[j+5],\r
- c.d.asBytes[j+6],\r
- c.d.asBytes[j+7],\r
- c.d.asBytes[j+8]\r
+ sample_buf[j+0],\r
+ sample_buf[j+1],\r
+ sample_buf[j+2],\r
+ sample_buf[j+3],\r
+ sample_buf[j+4],\r
+ sample_buf[j+5],\r
+ sample_buf[j+6],\r
+ sample_buf[j+7],\r
+ sample_buf[j+8]\r
);\r
delivered += 8;\r
- if(delivered >= requested)\r
+ if (delivered >= requested)\r
break;\r
}\r
- if(delivered >= requested)\r
+ if (delivered >= requested)\r
break;\r
}\r
}\r
static void CmdHisampless(char *str)\r
{\r
int cnt = 0;\r
- int i;\r
- int n;\r
- int j;\r
+ int i, j;\r
+ int n = strtol(str, NULL, 0);\r
\r
- if(atoi(str) == 0) {\r
+ if(n == 0) {\r
n = 1000;\r
} else {\r
- n = atoi(str)/4;\r
+ n/= 4;\r
}\r
\r
for(i = 0; i < n; i += 12) {\r
- UsbCommand c;\r
- c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K;\r
- c.arg[0] = i;\r
- SendCommand(&c, false);\r
- ReceiveCommand(&c);\r
- if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) {\r
- PrintToScrollback("bad resp");\r
- return;\r
- }\r
+ UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};\r
+ SendCommand(&c);\r
+ wait_for_response(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);\r
for(j = 0; j < 48; j++) {\r
- GraphBuffer[cnt++] = (int)((signed char)c.d.asBytes[j]);\r
+ GraphBuffer[cnt++] = (int)(sample_buf[j]);\r
}\r
}\r
GraphTraceLen = cnt;\r
int isum, qsum;\r
int outOfWeakAt;\r
bool negateI, negateQ;\r
- uint8_t first, second;\r
\r
uint8_t data[256];\r
int dataLen=0;\r
PrintToScrollback("make it to demod loop");\r
\r
for(;;) {\r
- uint16_t shiftReg = 0;\r
iold = i;\r
while(GraphBuffer[i] >= 0 && i < GraphTraceLen)\r
i++;\r
if(i >= GraphTraceLen) goto demodError;\r
if((i - iold) > 6) goto demodError;\r
\r
+ uint16_t shiftReg = 0;\r
if(i + 20 >= GraphTraceLen) goto demodError;\r
\r
for(j = 0; j < 10; j++) {\r
}\r
}\r
\r
+ uint8_t first, second;\r
ComputeCrc14443(CRC_14443_B, data, dataLen-2, &first, &second);\r
PrintToScrollback("CRC: %02x %02x (%s)\n", first, second,\r
(first == data[dataLen-2] && second == data[dataLen-1]) ?\r
static void CmdHi14list(char *str)\r
{\r
uint8_t got[960];\r
- int i = 0;\r
- int prev = -1;\r
GetFromBigBuf(got, sizeof(got));\r
\r
PrintToScrollback("recorded activity:");\r
PrintToScrollback(" time :rssi: who bytes");\r
PrintToScrollback("---------+----+----+-----------");\r
\r
- for(i=0; i<900;) {\r
- bool isResponse;\r
- int len = got[i+8];\r
- int metric = *((uint32_t *)(got+i+4));\r
-\r
- int timestamp = *((uint32_t *)(got+i));\r
- uint8_t *frame = (got+i+9);\r
- char *crc;\r
- char metricString[100];\r
+ int i = 0;\r
+ int prev = -1;\r
\r
- char line[1000] = "";\r
- int j;\r
+ for(;;) {\r
+ if(i >= 900) {\r
+ break;\r
+ }\r
\r
+ bool isResponse;\r
+ int timestamp = *((uint32_t *)(got+i));\r
if(timestamp & 0x80000000) {\r
timestamp &= 0x7fffffff;\r
isResponse = 1;\r
} else {\r
isResponse = 0;\r
}\r
+ int metric = *((uint32_t *)(got+i+4));\r
+\r
+ int len = got[i+8];\r
\r
if(len > 100) {\r
break;\r
break;\r
}\r
\r
+ uint8_t *frame = (got+i+9);\r
+\r
+ char line[1000] = "";\r
+ int j;\r
for(j = 0; j < len; j++) {\r
sprintf(line+(j*3), "%02x ", frame[j]);\r
}\r
\r
+ char *crc;\r
if(len > 2) {\r
uint8_t b1, b2;\r
ComputeCrc14443(CRC_14443_B, frame, len-2, &b1, &b2);\r
crc = "(SHORT)";\r
}\r
\r
+ char metricString[100];\r
if(isResponse) {\r
sprintf(metricString, "%3d", metric);\r
} else {\r
static void CmdHi14alist(char *str)\r
{\r
uint8_t got[1920];\r
- int i = 0;\r
- int prev = -1;\r
-\r
GetFromBigBuf(got, sizeof(got));\r
\r
PrintToScrollback("recorded activity:");\r
PrintToScrollback(" ETU :rssi: who bytes");\r
PrintToScrollback("---------+----+----+-----------");\r
\r
- for(i=0;i<1900;) {\r
+ int i = 0;\r
+ int prev = -1;\r
+\r
+ for(;;) {\r
+ if(i >= 1900) {\r
+ break;\r
+ }\r
+\r
bool isResponse;\r
int timestamp = *((uint32_t *)(got+i));\r
- int metric = 0;\r
- int parityBits = *((uint32_t *)(got+i+4));\r
- int len = got[i+8];\r
- char line[1000] = "";\r
- int j;\r
- uint8_t *frame = (got+i+9);\r
- const char *crc;\r
- char metricString[100];\r
-\r
if(timestamp & 0x80000000) {\r
timestamp &= 0x7fffffff;\r
isResponse = 1;\r
isResponse = 0;\r
}\r
\r
+ int metric = 0;\r
+ int parityBits = *((uint32_t *)(got+i+4));\r
// 4 bytes of additional information...\r
// maximum of 32 additional parity bit information\r
//\r
// or each half bit period in 256 levels.\r
\r
\r
+ int len = got[i+8];\r
+\r
if(len > 100) {\r
break;\r
}\r
break;\r
}\r
\r
+ uint8_t *frame = (got+i+9);\r
+\r
// Break and stick with current result if buffer was not completely full\r
if(frame[0] == 0x44 && frame[1] == 0x44 && frame[3] == 0x44) { break; }\r
\r
+ char line[1000] = "";\r
+ int j;\r
for(j = 0; j < len; j++) {\r
int oddparity = 0x01;\r
int k;\r
}\r
}\r
\r
+ char *crc;\r
crc = "";\r
if(len > 2) {\r
uint8_t b1, b2;\r
crc = ""; // SHORT\r
}\r
\r
+ char metricString[100];\r
if(isResponse) {\r
sprintf(metricString, "%3d", metric);\r
} else {\r
int max = 0, maxPos;\r
\r
int skip = 4;\r
- int k = 0;\r
- uint8_t outBuf[20];\r
- uint8_t mask = 0x01;\r
\r
if(GraphTraceLen < 1000) return;\r
\r
max/(arraylen(FrameSOF)/skip));\r
\r
i = maxPos + arraylen(FrameSOF)/skip;\r
+ int k = 0;\r
+ uint8_t outBuf[20];\r
memset(outBuf, 0, sizeof(outBuf));\r
+ uint8_t mask = 0x01;\r
for(;;) {\r
int corr0 = 0, corr1 = 0, corrEOF = 0;\r
for(j = 0; j < arraylen(Logic0); j += skip) {\r
\r
int i, j;\r
int minMark=0, maxMark=0;\r
- int max = 0, maxPos = 0;\r
- uint8_t bits[46];\r
\r
for(i = 0; i < GraphTraceLen - convLen; i++) {\r
int lowSum = 0, highSum = 0;\r
RepaintGraphWindow();\r
\r
// Find bit-sync (3 lo followed by 3 high)\r
+ int max = 0, maxPos = 0;\r
for(i = 0; i < 6000; i++) {\r
int dec = 0;\r
for(j = 0; j < 3*lowLen; j++) {\r
PrintToScrollback("actual data bits start at sample %d", maxPos);\r
PrintToScrollback("length %d/%d", highLen, lowLen);\r
\r
+ uint8_t bits[46];\r
bits[sizeof(bits)-1] = '\0';\r
\r
// find bit pairs and manchester decode them\r
// read a TI tag and return its ID\r
static void CmdTIRead(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_READ_TI_TYPE;\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_READ_TI_TYPE};\r
+ SendCommand(&c);\r
}\r
\r
// write new data to a r/w TI tag\r
static void CmdTIWrite(char *str)\r
{\r
- UsbCommand c;\r
+ UsbCommand c={CMD_WRITE_TI_TYPE};\r
int res=0;\r
\r
- c.cmd = CMD_WRITE_TI_TYPE;\r
res = sscanf(str, "0x%x 0x%x 0x%x ", &c.arg[0], &c.arg[1], &c.arg[2]);\r
if (res == 2) c.arg[2]=0;\r
if (res<2)\r
PrintToScrollback("Please specify the data as two hex strings, optionally the CRC as a third");\r
else\r
- SendCommand(&c, false);\r
+ SendCommand(&c);\r
}\r
\r
static void CmdTIDemod(char *cmdline)\r
int convLen = (highLen>lowLen)?highLen:lowLen;\r
uint16_t crc;\r
int i, j, TagType;\r
- int lowSum = 0, highSum = 0;\r
+ int lowSum = 0, highSum = 0;;\r
int lowTot = 0, highTot = 0;\r
- int max = 0, maxPos = 0;\r
- uint8_t bits[1+64+16+8+16];\r
- uint32_t shift3 = 0x7e000000, shift2 = 0, shift1 = 0, shift0 = 0;\r
-\r
\r
for(i = 0; i < GraphTraceLen - convLen; i++) {\r
lowSum = 0;\r
// Okay, so now we have unsliced soft decisions;\r
// find bit-sync, and then get some bits.\r
// look for 17 low bits followed by 6 highs (common pattern for ro and rw tags)\r
+ int max = 0, maxPos = 0;\r
for(i = 0; i < 6000; i++) {\r
int j;\r
int dec = 0;\r
\r
PrintToScrollback("length %d/%d", highLen, lowLen);\r
\r
+ uint8_t bits[1+64+16+8+16];\r
bits[sizeof(bits)-1] = '\0';\r
\r
+ uint32_t shift3 = 0x7e000000, shift2 = 0, shift1 = 0, shift0 = 0;\r
+\r
for(i = 0; i < arraylen(bits)-1; i++) {\r
int high = 0;\r
int low = 0;\r
static void CmdZerocrossings(char *str)\r
{\r
int i;\r
- int sign = 1;\r
- int zc = 0;\r
- int lastZc = 0;\r
// Zero-crossings aren't meaningful unless the signal is zero-mean.\r
CmdHpf("");\r
\r
+ int sign = 1;\r
+ int zc = 0;\r
+ int lastZc = 0;\r
for(i = 0; i < GraphTraceLen; i++) {\r
if(GraphBuffer[i]*sign >= 0) {\r
// No change in sign, reproduce the previous sample count.\r
static void CmdAutoCorr(char *str)\r
{\r
static int CorrelBuffer[MAX_GRAPH_TRACE_LEN];\r
- int i;\r
\r
int window = atoi(str);\r
\r
\r
PrintToScrollback("performing %d correlations", GraphTraceLen - window);\r
\r
+ int i;\r
for(i = 0; i < GraphTraceLen - window; i++) {\r
int sum = 0;\r
int j;\r
// So first, we correlate for the sync pattern, and mark that.\r
int bestCorrel = 0, bestPos = 0;\r
int i;\r
- char bits[257];\r
- int worst = INT_MAX;\r
- int worstPos;\r
-\r
// It does us no good to find the sync pattern, with fewer than\r
// 2048 samples after it...\r
for(i = 0; i < (GraphTraceLen-2048); i++) {\r
}\r
PrintToScrollback("best sync at %d [metric %d]", bestPos, bestCorrel);\r
\r
+ char bits[257];\r
bits[256] = '\0';\r
\r
+ int worst = INT_MAX;\r
+ int worstPos;\r
+\r
for(i = 0; i < 2048; i += 8) {\r
int sum = 0;\r
int j;\r
PrintToScrollback("worst metric: %d at pos %d", worst, worstPos);\r
\r
if(strcmp(str, "clone")==0) {\r
- char *s;\r
GraphTraceLen = 0;\r
+ char *s;\r
for(s = bits; *s; s++) {\r
int j;\r
for(j = 0; j < 16; j++) {\r
int state = -1;\r
int count = 0;\r
int i, j;\r
- int uidlen, long_wait;\r
// worst case with GraphTraceLen=64000 is < 4096\r
// under normal conditions it's < 2048\r
uint8_t rawbits[4096];\r
int rawbit = 0;\r
int worst = 0, worstPos = 0;\r
- int start;\r
- int first = 0;\r
- uint8_t bits[224];\r
- char showbits[225];\r
- int bit;\r
- int times = 0;\r
- int phase = 0;\r
-\r
PrintToScrollback("Expecting a bit less than %d raw bits", GraphTraceLen/32);\r
for(i = 0; i < GraphTraceLen-1; i += 2) {\r
count+=1;\r
PrintToScrollback("worst metric (0=best..7=worst): %d at pos %d", worst, worstPos);\r
\r
// Finding the start of a UID\r
+ int uidlen, long_wait;\r
if(strcmp(str, "224") == 0) {\r
uidlen=224;\r
long_wait=30;\r
uidlen=64;\r
long_wait=29;\r
}\r
+ int start;\r
+ int first = 0;\r
for(start = 0; start <= rawbit - uidlen; start++) {\r
first = rawbits[start];\r
for(i = start; i < start + long_wait; i++) {\r
}\r
\r
// Dumping UID\r
+ uint8_t bits[224];\r
+ char showbits[225];\r
showbits[uidlen]='\0';\r
+ int bit;\r
i = start;\r
+ int times = 0;\r
if(uidlen > rawbit) {\r
PrintToScrollback("Warning: not enough raw bits to get a full UID");\r
for(bit = 0; bit < rawbit; bit++) {\r
// Remodulating for tag cloning\r
GraphTraceLen = 32*uidlen;\r
i = 0;\r
+ int phase = 0;\r
for(bit = 0; bit < uidlen; bit++) {\r
- int j;\r
if(bits[bit] == 0) {\r
phase = 0;\r
} else {\r
phase = 1;\r
}\r
+ int j;\r
for(j = 0; j < 32; j++) {\r
GraphBuffer[i++] = phase;\r
phase = !phase;\r
static void CmdFlexdemod(char *str)\r
{\r
int i;\r
- int start;\r
- uint8_t bits[64];\r
-\r
- int bit;\r
- int phase = 0;\r
- \r
for(i = 0; i < GraphTraceLen; i++) {\r
if(GraphBuffer[i] < 0) {\r
GraphBuffer[i] = -1;\r
}\r
\r
#define LONG_WAIT 100\r
+ int start;\r
for(start = 0; start < GraphTraceLen - LONG_WAIT; start++) {\r
int first = GraphBuffer[start];\r
for(i = start; i < start + LONG_WAIT; i++) {\r
GraphBuffer[start] = 2;\r
GraphBuffer[start+1] = -2;\r
\r
+ uint8_t bits[64];\r
+\r
+ int bit;\r
i = start;\r
for(bit = 0; bit < 64; bit++) {\r
int j;\r
\r
GraphTraceLen = 32*64;\r
i = 0;\r
+ int phase = 0;\r
for(bit = 0; bit < 64; bit++) {\r
- int j;\r
if(bits[bit] == 0) {\r
phase = 0;\r
} else {\r
phase = 1;\r
}\r
+ int j;\r
for(j = 0; j < 32; j++) {\r
GraphBuffer[i++] = phase;\r
phase = !phase;\r
int bitidx = 0;\r
int bit2idx = 0;\r
int warnings = 0;\r
- int tolerance;\r
- /* Holds the decoded bitstream: each clock period contains 2 bits */\r
- /* later simplified to 1 bit after manchester decoding. */\r
- /* Add 10 bits to allow for noisy / uncertain traces without aborting */\r
- /* int BitStream[GraphTraceLen*2/clock+10]; */\r
-\r
- /* But it does not work if compiling on WIndows: therefore we just allocate a */\r
- /* large array */\r
- int BitStream[MAX_GRAPH_TRACE_LEN];\r
-\r
\r
/* check if we're inverting output */\r
if(*str == 'i')\r
while(*str == ' '); // in case a 2nd argument was given\r
}\r
\r
+ /* Holds the decoded bitstream: each clock period contains 2 bits */\r
+ /* later simplified to 1 bit after manchester decoding. */\r
+ /* Add 10 bits to allow for noisy / uncertain traces without aborting */\r
+ /* int BitStream[GraphTraceLen*2/clock+10]; */\r
+\r
+ /* But it does not work if compiling on WIndows: therefore we just allocate a */\r
+ /* large array */\r
+ int BitStream[MAX_GRAPH_TRACE_LEN];\r
+\r
/* Detect high and lows */\r
for (i = 0; i < GraphTraceLen; i++)\r
{\r
/* Get our clock */\r
clock = GetClock(str, high);\r
\r
- tolerance = clock/4;\r
+ int tolerance = clock/4;\r
\r
/* Detect first transition */\r
/* Lo-Hi (arbitrary) */\r
*/\r
static void CmdHiddemod(char *str)\r
{\r
- int i;\r
if(GraphTraceLen < 4800) {\r
PrintToScrollback("too short; need at least 4800 samples");\r
return;\r
}\r
\r
GraphTraceLen = 4800;\r
+ int i;\r
for(i = 0; i < GraphTraceLen; i++) {\r
if(GraphBuffer[i] < 0) {\r
GraphBuffer[i] = 0;\r
\r
static void CmdSave(char *str)\r
{\r
- int i;\r
FILE *f = fopen(str, "w");\r
if(!f) {\r
PrintToScrollback("couldn't open '%s'", str);\r
return;\r
}\r
+ int i;\r
for(i = 0; i < GraphTraceLen; i++) {\r
fprintf(f, "%d\n", GraphBuffer[i]);\r
}\r
\r
static void CmdLoad(char *str)\r
{\r
- char line[80];\r
FILE *f = fopen(str, "r");\r
if(!f) {\r
PrintToScrollback("couldn't open '%s'", str);\r
}\r
\r
GraphTraceLen = 0;\r
+ char line[80];\r
while(fgets(line, sizeof(line), f)) {\r
GraphBuffer[GraphTraceLen] = atoi(line);\r
GraphTraceLen++;\r
{\r
unsigned int hi=0, lo=0;\r
int n=0, i=0;\r
- UsbCommand c;\r
\r
while (sscanf(&str[i++], "%1x", &n ) == 1) {\r
hi=(hi<<4)|(lo>>28);\r
\r
PrintToScrollback("Emulating tag with ID %x%16x", hi, lo);\r
\r
- c.cmd = CMD_HID_SIM_TAG;\r
- c.arg[0] = hi;\r
- c.arg[1] = lo;\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_HID_SIM_TAG, {hi, lo, 0}};\r
+ SendCommand(&c);\r
}\r
\r
static void CmdReadmem(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_READ_MEM;\r
- c.arg[0] = atoi(str);\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_READ_MEM, {strtol(str, NULL, 0), 0, 0}};\r
+ SendCommand(&c);\r
}\r
\r
static void CmdVersion(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_VERSION;\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_VERSION};\r
+ SendCommand(&c);\r
}\r
\r
static void CmdLcdReset(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_LCD_RESET;\r
- c.arg[0] = atoi(str);\r
- SendCommand(&c, false);\r
+ UsbCommand c={CMD_LCD_RESET, {strtol(str, NULL, 0), 0, 0}};\r
+ SendCommand(&c);\r
}\r
\r
static void CmdLcd(char *str)\r
{\r
int i, j;\r
- UsbCommand c;\r
- c.cmd = CMD_LCD;\r
+ UsbCommand c={CMD_LCD};\r
sscanf(str, "%x %d", &i, &j);\r
while (j--) {\r
c.arg[0] = i&0x1ff;\r
- SendCommand(&c, false);\r
+ SendCommand(&c);\r
}\r
}\r
\r
*/\r
static void CmdSetDivisor(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_SET_LF_DIVISOR;\r
- c.arg[0] = atoi(str);\r
+ UsbCommand c={CMD_SET_LF_DIVISOR, {strtol(str, NULL, 0), 0, 0}};\r
if (( c.arg[0]<0) || (c.arg[0]>255)) {\r
PrintToScrollback("divisor must be between 19 and 255");\r
} else {\r
- SendCommand(&c, false);\r
+ SendCommand(&c);\r
PrintToScrollback("Divisor set, expected freq=%dHz", 12000000/(c.arg[0]+1));\r
}\r
}\r
\r
static void CmdSetMux(char *str)\r
{\r
- UsbCommand c;\r
- c.cmd = CMD_SET_ADC_MUX;\r
+ UsbCommand c={CMD_SET_ADC_MUX};\r
if(strcmp(str, "lopkd") == 0) {\r
c.arg[0] = 0;\r
} else if(strcmp(str, "loraw") == 0) {\r
} else if(strcmp(str, "hiraw") == 0) {\r
c.arg[0] = 3;\r
}\r
- SendCommand(&c, false);\r
+ SendCommand(&c);\r
}\r
\r
typedef void HandlerFunction(char *cmdline);\r
int offline; // 1 if the command can be used when in offline mode\r
char *docString;\r
} CommandTable[] = {\r
- {"amp", CmdAmp, 1, "Amplify peaks"},\r
- {"askdemod", Cmdaskdemod, 1, "<0|1> -- Attempt to demodulate simple ASK tags"},\r
- {"autocorr", CmdAutoCorr, 1, "<window length> -- Autocorrelation over window"},\r
- {"bitsamples", CmdBitsamples, 0, "Get raw samples as bitstring"},\r
- {"bitstream", Cmdbitstream, 1, "[clock rate] -- Convert waveform into a bitstream"},\r
- {"buffclear", CmdBuffClear, 1, "Clear sample buffer and graph window"},\r
- {"dec", CmdDec, 1, "Decimate samples"},\r
+ {"amp", CmdAmp, 1, "Amplify peaks"},\r
+ {"askdemod", Cmdaskdemod, 1, "<0|1> -- Attempt to demodulate simple ASK tags"},\r
+ {"autocorr", CmdAutoCorr, 1, "<window length> -- Autocorrelation over window"},\r
+ {"bitsamples", CmdBitsamples, 0, "Get raw samples as bitstring"},\r
+ {"bitstream", Cmdbitstream, 1, "[clock rate] -- Convert waveform into a bitstream"},\r
+ {"buffclear", CmdBuffClear, 1, "Clear sample buffer and graph window"},\r
+ {"dec", CmdDec, 1, "Decimate samples"},\r
{"detectclock", Cmddetectclockrate, 1, "Detect clock rate"},\r
- {"detectreader", CmdDetectReader, 0, "['l'|'h'] -- Detect external reader field (option 'l' or 'h' to limit to LF or HF)"},\r
- {"em410xsim", CmdEM410xsim, 1, "<UID> -- Simulate EM410x tag"},\r
- {"em410xread", CmdEM410xread, 1, "[clock rate] -- Extract ID from EM410x tag"},\r
- {"em410xwatch", CmdEM410xwatch, 0, "Watches for EM410x tags"},\r
- {"em4x50read", CmdEM4x50read, 1, "Extract data from EM4x50 tag"},\r
- {"exit", CmdQuit, 1, "Exit program"},\r
- {"flexdemod", CmdFlexdemod, 1, "Demodulate samples for FlexPass"},\r
- {"fpgaoff", CmdFPGAOff, 0, "Set FPGA off"},\r
- {"fskdemod", CmdFSKdemod, 1, "Demodulate graph window as a HID FSK"},\r
- {"grid", CmdGrid, 1, "<x> <y> -- overlay grid on graph window, use zero value to turn off either"},\r
- {"hexsamples", CmdHexsamples, 0, "<blocks> -- Dump big buffer as hex bytes"},\r
- {"hi14alist", CmdHi14alist, 0, "List ISO 14443a history"},\r
- {"hi14areader", CmdHi14areader, 0, "Act like an ISO14443 Type A reader"},\r
- {"hi14asim", CmdHi14asim, 0, "<UID> -- Fake ISO 14443a tag"},\r
- {"hi14asnoop", CmdHi14asnoop, 0, "Eavesdrop ISO 14443 Type A"},\r
- {"hi14bdemod", CmdHi14bdemod, 1, "Demodulate ISO14443 Type B from tag"},\r
- {"hi14list", CmdHi14list, 0, "List ISO 14443 history"},\r
- {"hi14read", CmdHi14read, 0, "Read HF tag (ISO 14443)"},\r
- {"hi14sim", CmdHi14sim, 0, "Fake ISO 14443 tag"},\r
- {"hi14snoop", CmdHi14snoop, 0, "Eavesdrop ISO 14443"},\r
- {"hi15demod", CmdHi15demod, 1, "Demodulate ISO15693 from tag"},\r
- {"hi15read", CmdHi15read, 0, "Read HF tag (ISO 15693)"},\r
- {"hi15reader", CmdHi15reader, 0, "Act like an ISO15693 reader"},\r
- {"hi15sim", CmdHi15tag, 0, "Fake an ISO15693 tag"},\r
- {"hiddemod", CmdHiddemod, 1, "Demodulate HID Prox Card II (not optimal)"},\r
- {"hide", CmdHide, 1, "Hide graph window"},\r
- {"hidfskdemod", CmdHIDdemodFSK, 0, "Realtime HID FSK demodulator"},\r
- {"hidsimtag", CmdHIDsimTAG, 0, "<ID> -- HID tag simulator"},\r
- {"higet", CmdHi14read_sim, 0, "<samples> -- Get samples HF, 'analog'"},\r
- {"hisamples", CmdHisamples, 0, "Get raw samples for HF tag"},\r
- {"hisampless", CmdHisampless, 0, "<samples> -- Get signed raw samples, HF tag"},\r
- {"hisamplest", CmdHi14readt, 0, "Get samples HF, for testing"},\r
- {"hisimlisten", CmdHisimlisten, 0, "Get HF samples as fake tag"},\r
- {"hpf", CmdHpf, 1, "Remove DC offset from trace"},\r
- {"indalademod", CmdIndalademod, 0, "['224'] -- Demodulate samples for Indala 64 bit UID (option '224' for 224 bit)"},\r
- {"lcd", CmdLcd, 0, "<HEX command> <count> -- Send command/data to LCD"},\r
- {"lcdreset", CmdLcdReset, 0, "Hardware reset LCD"},\r
- {"legicrfsim", CmdLegicRfSim, 0, "Start the LEGIC RF tag simulator"},\r
- {"legicrfread", CmdLegicRfRead, 0, "Start the LEGIC RF reader"},\r
- {"load", CmdLoad, 1, "<filename> -- Load trace (to graph window"},\r
- {"locomread", CmdLoCommandRead, 0, "<off period> <'0' period> <'1' period> <command> ['h'] -- Modulate LF reader field to send command before read (all periods in microseconds) (option 'h' for 134)"},\r
- {"loread", CmdLoread, 0, "['h'] -- Read 125/134 kHz LF ID-only tag (option 'h' for 134)"},\r
- {"losamples", CmdLosamples, 0, "[128 - 16000] -- Get raw samples for LF tag"},\r
- {"losim", CmdLosim, 0, "Simulate LF tag"},\r
- {"losimbidir", CmdLosimBidir, 0, "Simulate LF tag (with bidirectional data transmission between reader and tag)"},\r
- {"ltrim", CmdLtrim, 1, "<samples> -- Trim samples from left of trace"},\r
- {"mandemod", Cmdmanchesterdemod, 1, "[i] [clock rate] -- Manchester demodulate binary stream (option 'i' to invert output)"},\r
- {"manmod", Cmdmanchestermod, 1, "[clock rate] -- Manchester modulate a binary stream"},\r
- {"norm", CmdNorm, 1, "Normalize max/min to +/-500"},\r
- {"plot", CmdPlot, 1, "Show graph window"},\r
- {"quit", CmdQuit, 1, "Quit program"},\r
- {"readmem", CmdReadmem, 0, "[address] -- Read memory at decimal address from flash"},\r
- {"reset", CmdReset, 0, "Reset the Proxmark3"},\r
- {"save", CmdSave, 1, "<filename> -- Save trace (from graph window)"},\r
- {"scale", CmdScale, 1, "<int> -- Set cursor display scale"},\r
- {"setlfdivisor", CmdSetDivisor, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},\r
- {"setmux", CmdSetMux, 0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},\r
- {"sri512read", CmdSri512read, 0, "<int> -- Read contents of a SRI512 tag"},\r
- {"srix4kread", CmdSrix4kread, 0, "<int> -- Read contents of a SRIX4K tag"},\r
- {"tidemod", CmdTIDemod, 1, "Demodulate raw bits for TI-type LF tag"},\r
- {"tiread", CmdTIRead, 0, "Read and decode a TI 134 kHz tag"},\r
- {"tiwrite", CmdTIWrite, 0, "Write new data to a r/w TI 134 kHz tag"},\r
- {"threshold", CmdThreshold, 1, "Maximize/minimize every value in the graph window depending on threshold"},\r
- {"tune", CmdTune, 0, "Measure antenna tuning"},\r
- {"vchdemod", CmdVchdemod, 0, "['clone'] -- Demodulate samples for VeriChip"},\r
- {"version", CmdVersion, 0, "Show version inforation about the connected Proxmark"},\r
- {"zerocrossings", CmdZerocrossings, 1, "Count time between zero-crossings"},\r
+ {"detectreader", CmdDetectReader, 0, "['l'|'h'] -- Detect external reader field (option 'l' or 'h' to limit to LF or HF)"},\r
+ {"em410xsim", CmdEM410xsim, 1, "<UID> -- Simulate EM410x tag"},\r
+ {"em410xread", CmdEM410xread, 1, "[clock rate] -- Extract ID from EM410x tag"},\r
+ {"em410xwatch", CmdEM410xwatch, 0, "Watches for EM410x tags"},\r
+ {"em4x50read", CmdEM4x50read, 1, "Extract data from EM4x50 tag"},\r
+ {"exit", CmdQuit, 1, "Exit program"},\r
+ {"flexdemod", CmdFlexdemod, 1, "Demodulate samples for FlexPass"},\r
+ {"fpgaoff", CmdFPGAOff, 0, "Set FPGA off"},\r
+ {"fskdemod", CmdFSKdemod, 1, "Demodulate graph window as a HID FSK"},\r
+ {"grid", CmdGrid, 1, "<x> <y> -- overlay grid on graph window, use zero value to turn off either"},\r
+ {"hexsamples", CmdHexsamples, 0, "<blocks> -- Dump big buffer as hex bytes"},\r
+ {"hi14alist", CmdHi14alist, 0, "List ISO 14443a history"},\r
+ {"hi14amifare", CmdHi14amifare, 0, "Read out sector 0 parity error messages"},\r
+ {"hi14areader", CmdHi14areader, 0, "Act like an ISO14443 Type A reader"},\r
+ {"hi14asim", CmdHi14asim, 0, "<UID> -- Fake ISO 14443a tag"},\r
+ {"hi14asnoop", CmdHi14asnoop, 0, "Eavesdrop ISO 14443 Type A"},\r
+ {"hi14bdemod", CmdHi14bdemod, 1, "Demodulate ISO14443 Type B from tag"},\r
+ {"hi14list", CmdHi14list, 0, "List ISO 14443 history"},\r
+ {"hi14read", CmdHi14read, 0, "Read HF tag (ISO 14443)"},\r
+ {"hi14sim", CmdHi14sim, 0, "Fake ISO 14443 tag"},\r
+ {"hi14snoop", CmdHi14snoop, 0, "Eavesdrop ISO 14443"},\r
+ {"hi15demod", CmdHi15demod, 1, "Demodulate ISO15693 from tag"},\r
+ {"hi15read", CmdHi15read, 0, "Read HF tag (ISO 15693)"},\r
+ {"hi15reader", CmdHi15reader, 0, "Act like an ISO15693 reader"},\r
+ {"hi15sim", CmdHi15tag, 0, "Fake an ISO15693 tag"},\r
+ {"hiddemod", CmdHiddemod, 1, "Demodulate HID Prox Card II (not optimal)"},\r
+ {"hide", CmdHide, 1, "Hide graph window"},\r
+ {"hidfskdemod", CmdHIDdemodFSK, 0, "Realtime HID FSK demodulator"},\r
+ {"hidsimtag", CmdHIDsimTAG, 0, "<ID> -- HID tag simulator"},\r
+ {"higet", CmdHi14read_sim, 0, "<samples> -- Get samples HF, 'analog'"},\r
+ {"hisamples", CmdHisamples, 0, "Get raw samples for HF tag"},\r
+ {"hisampless", CmdHisampless, 0, "<samples> -- Get signed raw samples, HF tag"},\r
+ {"hisamplest", CmdHi14readt, 0, "Get samples HF, for testing"},\r
+ {"hisimlisten", CmdHisimlisten, 0, "Get HF samples as fake tag"},\r
+ {"hpf", CmdHpf, 1, "Remove DC offset from trace"},\r
+ {"indalademod", CmdIndalademod, 0, "['224'] -- Demodulate samples for Indala 64 bit UID (option '224' for 224 bit)"},\r
+ {"lcd", CmdLcd, 0, "<HEX command> <count> -- Send command/data to LCD"},\r
+ {"lcdreset", CmdLcdReset, 0, "Hardware reset LCD"},\r
+ {"legicrfread", CmdLegicRfRead, 0, "Start the LEGIC RF reader"},\r
+ {"load", CmdLoad, 1, "<filename> -- Load trace (to graph window"},\r
+ {"locomread", CmdLoCommandRead, 0, "<off period> <'0' period> <'1' period> <command> ['h'] -- Modulate LF reader field to send command before read (all periods in microseconds) (option 'h' for 134)"},\r
+ {"loread", CmdLoread, 0, "['h'] -- Read 125/134 kHz LF ID-only tag (option 'h' for 134)"},\r
+ {"losamples", CmdLosamples, 0, "[128 - 16000] -- Get raw samples for LF tag"},\r
+ {"losim", CmdLosim, 0, "Simulate LF tag"},\r
+ {"losimbidir", CmdLosimBidir, 0, "Simulate LF tag (with bidirectional data transmission between reader and tag)"},\r
+ {"ltrim", CmdLtrim, 1, "<samples> -- Trim samples from left of trace"},\r
+ {"mandemod", Cmdmanchesterdemod, 1, "[i] [clock rate] -- Manchester demodulate binary stream (option 'i' to invert output)"},\r
+ {"manmod", Cmdmanchestermod, 1, "[clock rate] -- Manchester modulate a binary stream"},\r
+ {"norm", CmdNorm, 1, "Normalize max/min to +/-500"},\r
+ {"plot", CmdPlot, 1, "Show graph window"},\r
+ {"quit", CmdQuit, 1, "Quit program"},\r
+ {"readmem", CmdReadmem, 0, "[address] -- Read memory at decimal address from flash"},\r
+ {"reset", CmdReset, 0, "Reset the Proxmark3"},\r
+ {"save", CmdSave, 1, "<filename> -- Save trace (from graph window)"},\r
+ {"scale", CmdScale, 1, "<int> -- Set cursor display scale"},\r
+ {"setlfdivisor", CmdSetDivisor, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},\r
+ {"setmux", CmdSetMux, 0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},\r
+ {"sri512read", CmdSri512read, 0, "<int> -- Read contents of a SRI512 tag"},\r
+ {"srix4kread", CmdSrix4kread, 0, "<int> -- Read contents of a SRIX4K tag"},\r
+ {"tidemod", CmdTIDemod, 1, "Demodulate raw bits for TI-type LF tag"},\r
+ {"tiread", CmdTIRead, 0, "Read and decode a TI 134 kHz tag"},\r
+ {"tiwrite", CmdTIWrite, 0, "Write new data to a r/w TI 134 kHz tag"},\r
+ {"threshold", CmdThreshold, 1, "Maximize/minimize every value in the graph window depending on threshold"},\r
+ {"tune", CmdTune, 0, "Measure antenna tuning"},\r
+ {"vchdemod", CmdVchdemod, 0, "['clone'] -- Demodulate samples for VeriChip"},\r
+ {"version", CmdVersion, 0, "Show version inforation about the connected Proxmark"},\r
+ {"zerocrossings", CmdZerocrossings, 1, "Count time between zero-crossings"},\r
};\r
\r
static struct {\r
//-----------------------------------------------------------------------------\r
void UsbCommandReceived(UsbCommand *c)\r
{\r
+// printf("%s(%x) current cmd = %x\n", __FUNCTION__, c->cmd, current_command);\r
+/* If we recognize a response, return to avoid further processing */\r
switch(c->cmd) {\r
case CMD_DEBUG_PRINT_STRING: {\r
char s[100];\r
memcpy(s, c->d.asBytes, c->arg[0]);\r
s[c->arg[0]] = '\0';\r
PrintToScrollback("#db# %s", s);\r
- break;\r
+ return;\r
}\r
\r
case CMD_DEBUG_PRINT_INTEGERS:\r
PrintToScrollback("#db# %08x, %08x, %08x\r\n", c->arg[0], c->arg[1], c->arg[2]);\r
- break;\r
+ return;\r
\r
case CMD_MEASURED_ANTENNA_TUNING: {\r
int peakv, peakf;\r
PrintToScrollback("# Your HF antenna is unusable.");\r
else if (vHf<5000)\r
PrintToScrollback("# Your HF antenna is marginal.");\r
- break;\r
+ return;\r
}\r
default:\r
- PrintToScrollback("unrecognized command %08x\n", c->cmd);\r
break;\r
}\r
+ /* Maybe it's a response: */\r
+ switch(current_command) {\r
+ case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K:\r
+ if (c->cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) goto unexpected_response;\r
+ int i;\r
+ for(i=0; i<48; i++) sample_buf[i] = c->d.asBytes[i];\r
+ received_command = c->cmd;\r
+ return;\r
+ default:\r
+ unexpected_response:\r
+ PrintToScrollback("unrecognized command %08x\n", c->cmd);\r
+ break;\r
+ }\r
}\r