change usb_cmd struct to be more sane

wean ourselves off translate.h
This commit is contained in:
bushing 2009-12-22 12:34:24 +00:00
parent cd00aa3043
commit 3a8464f067
7 changed files with 189 additions and 156 deletions

View file

@ -34,7 +34,7 @@ static void GetFromBigBuf(BYTE *dest, int bytes)
for(i = 0; i < n; i += 12) { for(i = 0; i < n; i += 12) {
UsbCommand c; UsbCommand c;
c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K; c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K;
c.ext1 = i; c.arg[0] = i;
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
ReceiveCommand(&c); ReceiveCommand(&c);
if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) { if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) {
@ -91,7 +91,7 @@ static void CmdHi14read(char *str)
{ {
UsbCommand c; UsbCommand c;
c.cmd = CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443; c.cmd = CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443;
c.ext1 = atoi(str); c.arg[0] = atoi(str);
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
} }
@ -104,30 +104,30 @@ static void CmdSri512read(char *str)
{ {
UsbCommand c; UsbCommand c;
c.cmd = CMD_READ_SRI512_TAG; c.cmd = CMD_READ_SRI512_TAG;
c.ext1 = atoi(str); c.arg[0] = atoi(str);
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
} }
/* New command to read the contents of a SRIX4K tag /* New command to read the contents of a SRIX4K tag
* SRIX4K tags are ISO14443-B modulated memory tags, * SRIX4K tags are ISO14443-B modulated memory tags,
* this command just dumps the contents of the memory/ * this command just dumps the contents of the memory/
*/ */
static void CmdSrix4kread(char *str) static void CmdSrix4kread(char *str)
{ {
UsbCommand c; UsbCommand c;
c.cmd = CMD_READ_SRIX4K_TAG; c.cmd = CMD_READ_SRIX4K_TAG;
c.ext1 = atoi(str); c.arg[0] = atoi(str);
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
} }
// ## New command // ## New command
static void CmdHi14areader(char *str) static void CmdHi14areader(char *str)
{ {
UsbCommand c; UsbCommand c;
c.cmd = CMD_READER_ISO_14443a; c.cmd = CMD_READER_ISO_14443a;
c.ext1 = atoi(str); c.arg[0] = atoi(str);
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
} }
@ -136,7 +136,7 @@ static void CmdHi15reader(char *str)
{ {
UsbCommand c; UsbCommand c;
c.cmd = CMD_READER_ISO_15693; c.cmd = CMD_READER_ISO_15693;
c.ext1 = atoi(str); c.arg[0] = atoi(str);
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
} }
@ -145,7 +145,7 @@ static void CmdHi15tag(char *str)
{ {
UsbCommand c; UsbCommand c;
c.cmd = CMD_SIMTAG_ISO_15693; c.cmd = CMD_SIMTAG_ISO_15693;
c.ext1 = atoi(str); c.arg[0] = atoi(str);
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
} }
@ -153,7 +153,7 @@ static void CmdHi14read_sim(char *str)
{ {
UsbCommand c; UsbCommand c;
c.cmd = CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM; c.cmd = CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM;
c.ext1 = atoi(str); c.arg[0] = atoi(str);
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
} }
@ -161,13 +161,13 @@ static void CmdHi14readt(char *str)
{ {
UsbCommand c; UsbCommand c;
c.cmd = CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443; c.cmd = CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443;
c.ext1 = atoi(str); c.arg[0] = atoi(str);
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
//CmdHisamplest(str); //CmdHisamplest(str);
while(CmdHisamplest(str,atoi(str))==0) { while(CmdHisamplest(str,atoi(str))==0) {
c.cmd = CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443; c.cmd = CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443;
c.ext1 = atoi(str); c.arg[0] = atoi(str);
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
} }
RepaintGraphWindow(); RepaintGraphWindow();
@ -201,8 +201,8 @@ static void CmdHi14asim(char *str) // ## simulate iso14443a tag
c.cmd = CMD_SIMULATE_TAG_ISO_14443a; c.cmd = CMD_SIMULATE_TAG_ISO_14443a;
// c.ext should be set to *str or convert *str to the correct format for a uid // c.ext should be set to *str or convert *str to the correct format for a uid
c.ext1 = hi; c.arg[0] = hi;
c.ext2 = lo; c.arg[1] = lo;
PrintToScrollback("Emulating 14443A TAG with UID %x%16x", hi, lo); PrintToScrollback("Emulating 14443A TAG with UID %x%16x", hi, lo);
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
} }
@ -681,13 +681,13 @@ static void CmdLosim(char *str)
c.d.asBytes[j] = GraphBuffer[i+j]; c.d.asBytes[j] = GraphBuffer[i+j];
} }
c.cmd = CMD_DOWNLOADED_SIM_SAMPLES_125K; c.cmd = CMD_DOWNLOADED_SIM_SAMPLES_125K;
c.ext1 = i; c.arg[0] = i;
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
} }
UsbCommand c; UsbCommand c;
c.cmd = CMD_SIMULATE_TAG_125K; c.cmd = CMD_SIMULATE_TAG_125K;
c.ext1 = GraphTraceLen; c.arg[0] = GraphTraceLen;
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
} }
@ -695,8 +695,8 @@ static void CmdLosimBidir(char *str)
{ {
UsbCommand c; UsbCommand c;
c.cmd = CMD_LF_SIMULATE_BIDIR; c.cmd = CMD_LF_SIMULATE_BIDIR;
c.ext1 = 47; /* Set ADC to twice the carrier for a slight supersampling */ c.arg[0] = 47; /* Set ADC to twice the carrier for a slight supersampling */
c.ext2 = 384; c.arg[1] = 384;
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
} }
@ -705,9 +705,9 @@ static void CmdLoread(char *str)
UsbCommand c; UsbCommand c;
// 'h' means higher-low-frequency, 134 kHz // 'h' means higher-low-frequency, 134 kHz
if(*str == 'h') { if(*str == 'h') {
c.ext1 = 1; c.arg[0] = 1;
} else if (*str == '\0') { } else if (*str == '\0') {
c.ext1 = 0; c.arg[0] = 0;
} else { } else {
PrintToScrollback("use 'loread' or 'loread h'"); PrintToScrollback("use 'loread' or 'loread h'");
return; return;
@ -721,9 +721,9 @@ static void CmdDetectReader(char *str)
UsbCommand c; UsbCommand c;
// 'l' means LF - 125/134 kHz // 'l' means LF - 125/134 kHz
if(*str == 'l') { if(*str == 'l') {
c.ext1 = 1; c.arg[0] = 1;
} else if (*str == 'h') { } else if (*str == 'h') {
c.ext1 = 2; c.arg[0] = 2;
} else if (*str != '\0') { } else if (*str != '\0') {
PrintToScrollback("use 'detectreader' or 'detectreader l' or 'detectreader h'"); PrintToScrollback("use 'detectreader' or 'detectreader l' or 'detectreader h'");
return; return;
@ -741,7 +741,7 @@ static void CmdLoCommandRead(char *str)
UsbCommand c; UsbCommand c;
c.cmd = CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K; c.cmd = CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K;
sscanf(str, "%i %i %i %s %s", &c.ext1, &c.ext2, &c.ext3, (char *) &c.d.asBytes,(char *) &dummy+1); sscanf(str, "%i %i %i %s %s", &c.arg[0], &c.arg[1], &c.arg[2], (char *) &c.d.asBytes,(char *) &dummy+1);
// in case they specified 'h' // in case they specified 'h'
strcpy((char *)&c.d.asBytes + strlen((char *)c.d.asBytes), dummy); strcpy((char *)&c.d.asBytes + strlen((char *)c.d.asBytes), dummy);
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
@ -760,7 +760,7 @@ static void CmdLosamples(char *str)
for(i = 0; i < n; i += 12) { for(i = 0; i < n; i += 12) {
UsbCommand c; UsbCommand c;
c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K; c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K;
c.ext1 = i; c.arg[0] = i;
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
ReceiveCommand(&c); ReceiveCommand(&c);
if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) { if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) {
@ -787,7 +787,7 @@ static void CmdBitsamples(char *str)
for(i = 0; i < n; i += 12) { for(i = 0; i < n; i += 12) {
UsbCommand c; UsbCommand c;
c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K; c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K;
c.ext1 = i; c.arg[0] = i;
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
ReceiveCommand(&c); ReceiveCommand(&c);
if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) { if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) {
@ -818,7 +818,7 @@ static void CmdHisamples(char *str)
for(i = 0; i < n; i += 12) { for(i = 0; i < n; i += 12) {
UsbCommand c; UsbCommand c;
c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K; c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K;
c.ext1 = i; c.arg[0] = i;
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
ReceiveCommand(&c); ReceiveCommand(&c);
if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) { if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) {
@ -850,7 +850,7 @@ static int CmdHisamplest(char *str, int nrlow)
for(i = 0; i < n; i += 12) { for(i = 0; i < n; i += 12) {
UsbCommand c; UsbCommand c;
c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K; c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K;
c.ext1 = i; c.arg[0] = i;
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
ReceiveCommand(&c); ReceiveCommand(&c);
if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) { if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) {
@ -922,7 +922,7 @@ static void CmdHexsamples(char *str)
for(i = 0; i < n; i += 12) { for(i = 0; i < n; i += 12) {
UsbCommand c; UsbCommand c;
c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K; c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K;
c.ext1 = i; c.arg[0] = i;
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
ReceiveCommand(&c); ReceiveCommand(&c);
if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) { if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) {
@ -966,7 +966,7 @@ static void CmdHisampless(char *str)
for(i = 0; i < n; i += 12) { for(i = 0; i < n; i += 12) {
UsbCommand c; UsbCommand c;
c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K; c.cmd = CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K;
c.ext1 = i; c.arg[0] = i;
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
ReceiveCommand(&c); ReceiveCommand(&c);
if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) { if(c.cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) {
@ -1577,8 +1577,8 @@ static void CmdTIWrite(char *str)
int res=0; int res=0;
c.cmd = CMD_WRITE_TI_TYPE; c.cmd = CMD_WRITE_TI_TYPE;
res = sscanf(str, "0x%x 0x%x 0x%x ", &c.ext1, &c.ext2, &c.ext3); res = sscanf(str, "0x%x 0x%x 0x%x ", &c.arg[0], &c.arg[1], &c.arg[2]);
if (res == 2) c.ext3=0; if (res == 2) c.arg[2]=0;
if (res<2) if (res<2)
PrintToScrollback("Please specify the data as two hex strings, optionally the CRC as a third"); PrintToScrollback("Please specify the data as two hex strings, optionally the CRC as a third");
else else
@ -2809,8 +2809,8 @@ static void CmdHIDsimTAG(char *str)
PrintToScrollback("Emulating tag with ID %x%16x", hi, lo); PrintToScrollback("Emulating tag with ID %x%16x", hi, lo);
c.cmd = CMD_HID_SIM_TAG; c.cmd = CMD_HID_SIM_TAG;
c.ext1 = hi; c.arg[0] = hi;
c.ext2 = lo; c.arg[1] = lo;
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
} }
@ -2818,7 +2818,7 @@ static void CmdReadmem(char *str)
{ {
UsbCommand c; UsbCommand c;
c.cmd = CMD_READ_MEM; c.cmd = CMD_READ_MEM;
c.ext1 = atoi(str); c.arg[0] = atoi(str);
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
} }
@ -2833,7 +2833,7 @@ static void CmdLcdReset(char *str)
{ {
UsbCommand c; UsbCommand c;
c.cmd = CMD_LCD_RESET; c.cmd = CMD_LCD_RESET;
c.ext1 = atoi(str); c.arg[0] = atoi(str);
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
} }
@ -2844,7 +2844,7 @@ static void CmdLcd(char *str)
c.cmd = CMD_LCD; c.cmd = CMD_LCD;
sscanf(str, "%x %d", &i, &j); sscanf(str, "%x %d", &i, &j);
while (j--) { while (j--) {
c.ext1 = i&0x1ff; c.arg[0] = i&0x1ff;
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
} }
} }
@ -2857,12 +2857,12 @@ static void CmdSetDivisor(char *str)
{ {
UsbCommand c; UsbCommand c;
c.cmd = CMD_SET_LF_DIVISOR; c.cmd = CMD_SET_LF_DIVISOR;
c.ext1 = atoi(str); c.arg[0] = atoi(str);
if (( c.ext1<0) || (c.ext1>255)) { if (( c.arg[0]<0) || (c.arg[0]>255)) {
PrintToScrollback("divisor must be between 19 and 255"); PrintToScrollback("divisor must be between 19 and 255");
} else { } else {
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
PrintToScrollback("Divisor set, expected freq=%dHz", 12000000/(c.ext1+1)); PrintToScrollback("Divisor set, expected freq=%dHz", 12000000/(c.arg[0]+1));
} }
} }
@ -2871,13 +2871,13 @@ static void CmdSetMux(char *str)
UsbCommand c; UsbCommand c;
c.cmd = CMD_SET_ADC_MUX; c.cmd = CMD_SET_ADC_MUX;
if(strcmp(str, "lopkd") == 0) { if(strcmp(str, "lopkd") == 0) {
c.ext1 = 0; c.arg[0] = 0;
} else if(strcmp(str, "loraw") == 0) { } else if(strcmp(str, "loraw") == 0) {
c.ext1 = 1; c.arg[0] = 1;
} else if(strcmp(str, "hipkd") == 0) { } else if(strcmp(str, "hipkd") == 0) {
c.ext1 = 2; c.arg[0] = 2;
} else if(strcmp(str, "hiraw") == 0) { } else if(strcmp(str, "hiraw") == 0) {
c.ext1 = 3; c.arg[0] = 3;
} }
SendCommand(&c, FALSE); SendCommand(&c, FALSE);
} }
@ -2957,7 +2957,7 @@ static struct {
{"setlfdivisor", CmdSetDivisor, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"}, {"setlfdivisor", CmdSetDivisor, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
{"setmux", CmdSetMux, 0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"}, {"setmux", CmdSetMux, 0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
{"sri512read", CmdSri512read, 0, "<int> -- Read contents of a SRI512 tag"}, {"sri512read", CmdSri512read, 0, "<int> -- Read contents of a SRI512 tag"},
{"srix4kread", CmdSrix4kread, 0, "<int> -- Read contents of a SRIX4K tag"}, {"srix4kread", CmdSrix4kread, 0, "<int> -- Read contents of a SRIX4K tag"},
{"tidemod", CmdTIDemod, 1, "Demodulate raw bits for TI-type LF tag"}, {"tidemod", CmdTIDemod, 1, "Demodulate raw bits for TI-type LF tag"},
{"tiread", CmdTIRead, 0, "Read and decode a TI 134 kHz tag"}, {"tiread", CmdTIRead, 0, "Read and decode a TI 134 kHz tag"},
{"tiwrite", CmdTIWrite, 0, "Write new data to a r/w TI 134 kHz tag"}, {"tiwrite", CmdTIWrite, 0, "Write new data to a r/w TI 134 kHz tag"},
@ -3049,27 +3049,27 @@ void UsbCommandReceived(UsbCommand *c)
switch(c->cmd) { switch(c->cmd) {
case CMD_DEBUG_PRINT_STRING: { case CMD_DEBUG_PRINT_STRING: {
char s[100]; char s[100];
if(c->ext1 > 70 || c->ext1 < 0) { if(c->arg[0] > 70 || c->arg[0] < 0) {
c->ext1 = 0; c->arg[0] = 0;
} }
memcpy(s, c->d.asBytes, c->ext1); memcpy(s, c->d.asBytes, c->arg[0]);
s[c->ext1] = '\0'; s[c->arg[0]] = '\0';
PrintToScrollback("#db# %s", s); PrintToScrollback("#db# %s", s);
break; break;
} }
case CMD_DEBUG_PRINT_INTEGERS: case CMD_DEBUG_PRINT_INTEGERS:
PrintToScrollback("#db# %08x, %08x, %08x\r\n", c->ext1, c->ext2, c->ext3); PrintToScrollback("#db# %08x, %08x, %08x\r\n", c->arg[0], c->arg[1], c->arg[2]);
break; break;
case CMD_MEASURED_ANTENNA_TUNING: { case CMD_MEASURED_ANTENNA_TUNING: {
int peakv, peakf; int peakv, peakf;
int vLf125, vLf134, vHf; int vLf125, vLf134, vHf;
vLf125 = c->ext1 & 0xffff; vLf125 = c->arg[0] & 0xffff;
vLf134 = c->ext1 >> 16; vLf134 = c->arg[0] >> 16;
vHf = c->ext2 & 0xffff;; vHf = c->arg[1] & 0xffff;;
peakf = c->ext3 & 0xffff; peakf = c->arg[2] & 0xffff;
peakv = c->ext3 >> 16; peakv = c->arg[2] >> 16;
PrintToScrollback(""); PrintToScrollback("");
PrintToScrollback(""); PrintToScrollback("");
PrintToScrollback("# LF antenna: %5.2f V @ 125.00 kHz", vLf125/1000.0); PrintToScrollback("# LF antenna: %5.2f V @ 125.00 kHz", vLf125/1000.0);

View file

@ -42,16 +42,16 @@ static void FlushPrevious(int translate)
for(i = 0; i < 240; i += 48) { for(i = 0; i < 240; i += 48) {
c.cmd = CMD_SETUP_WRITE; c.cmd = CMD_SETUP_WRITE;
memcpy(c.d.asBytes, QueuedToSend+i, 48); memcpy(c.d.asBytes, QueuedToSend+i, 48);
c.ext1 = (i/4); c.arg[0] = (i/4);
SendCommand(&c, TRUE); SendCommand(&c, TRUE);
} }
c.cmd = CMD_FINISH_WRITE; c.cmd = CMD_FINISH_WRITE;
c.ext1 = (ExpectedAddr-1) & (~255); c.arg[0] = (ExpectedAddr-1) & (~255);
if(translate) { if(translate) {
c.ext1 -= PHYSICAL_FLASH_START; c.arg[0] -= PHYSICAL_FLASH_START;
} }
printf("c.ext1 = %08x\r", c.ext1); printf("c.arg[0] = %08x\r", c.arg[0]);
memcpy(c.d.asBytes, QueuedToSend+240, 16); memcpy(c.d.asBytes, QueuedToSend+240, 16);
SendCommand(&c, TRUE); SendCommand(&c, TRUE);
@ -151,14 +151,14 @@ static int PrepareFlash(struct partition *p, const char *filename, unsigned int
if(state & DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH) { if(state & DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH) {
UsbCommand c; UsbCommand c;
c.cmd = CMD_START_FLASH; c.cmd = CMD_START_FLASH;
c.ext1 = p->start; c.arg[0] = p->start;
c.ext2 = p->end; c.arg[1] = p->end;
/* Only send magic when flashing bootrom */ /* Only send magic when flashing bootrom */
if(p->precious) { if(p->precious) {
c.ext3 = START_FLASH_MAGIC; c.arg[2] = START_FLASH_MAGIC;
} else { } else {
c.ext3 = 0; c.arg[2] = 0;
} }
SendCommand(&c, TRUE); SendCommand(&c, TRUE);
translate = 0; translate = 0;
@ -196,7 +196,7 @@ static unsigned int GetProxmarkState(void)
state = DEVICE_INFO_FLAG_CURRENT_MODE_OS; state = DEVICE_INFO_FLAG_CURRENT_MODE_OS;
break; break;
case CMD_DEVICE_INFO: case CMD_DEVICE_INFO:
state = resp.ext1; state = resp.arg[0];
break; break;
default: default:
fprintf(stderr, "Couldn't get proxmark state, bad response type: 0x%04X\n", resp.cmd); fprintf(stderr, "Couldn't get proxmark state, bad response type: 0x%04X\n", resp.cmd);

View file

@ -253,16 +253,16 @@ static void FlushPrevious(int translate)
for(i = 0; i < 240; i += 48) { for(i = 0; i < 240; i += 48) {
c.cmd = CMD_SETUP_WRITE; c.cmd = CMD_SETUP_WRITE;
memcpy(c.d.asBytes, QueuedToSend+i, 48); memcpy(c.d.asBytes, QueuedToSend+i, 48);
c.ext1 = (i/4); c.arg[0] = (i/4);
SendCommand(&c, TRUE); SendCommand(&c, TRUE);
} }
c.cmd = CMD_FINISH_WRITE; c.cmd = CMD_FINISH_WRITE;
c.ext1 = (ExpectedAddr-1) & (~255); c.arg[0] = (ExpectedAddr-1) & (~255);
if(translate) { if(translate) {
c.ext1 -= PHYSICAL_FLASH_START; c.arg[0] -= PHYSICAL_FLASH_START;
} }
printf("Flashing address: %08x\r", c.ext1); printf("Flashing address: %08x\r", c.arg[0]);
memcpy(c.d.asBytes, QueuedToSend+240, 16); memcpy(c.d.asBytes, QueuedToSend+240, 16);
SendCommand(&c, TRUE); SendCommand(&c, TRUE);
@ -362,14 +362,14 @@ static int PrepareFlash(struct partition *p, const char *filename, unsigned int
if(state & DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH) { if(state & DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH) {
UsbCommand c; UsbCommand c;
c.cmd = CMD_START_FLASH; c.cmd = CMD_START_FLASH;
c.ext1 = p->start; c.arg[0] = p->start;
c.ext2 = p->end; c.arg[1] = p->end;
/* Only send magic when flashing bootrom */ /* Only send magic when flashing bootrom */
if(p->precious) { if(p->precious) {
c.ext3 = START_FLASH_MAGIC; c.arg[2] = START_FLASH_MAGIC;
} else { } else {
c.ext3 = 0; c.arg[2] = 0;
} }
SendCommand(&c, TRUE); SendCommand(&c, TRUE);
translate = 0; translate = 0;
@ -407,7 +407,7 @@ static unsigned int GetProxmarkState(void)
state = DEVICE_INFO_FLAG_CURRENT_MODE_OS; state = DEVICE_INFO_FLAG_CURRENT_MODE_OS;
break; break;
case CMD_DEVICE_INFO: case CMD_DEVICE_INFO:
state = resp.ext1; state = resp.arg[0];
break; break;
default: default:
fprintf(stderr, "Couldn't get proxmark state, bad response type: 0x%04X\n", resp.cmd); fprintf(stderr, "Couldn't get proxmark state, bad response type: 0x%04X\n", resp.cmd);

View file

@ -1,15 +1,24 @@
#ifndef __PROX_H #ifndef __PROX_H
#define __PROX_H #define __PROX_H
#ifdef _MSC_VER
typedef DWORD uint32_t;
typedef BYTE uint8_t;
typedef WORD uint16_t;
#define bool BOOL
#else
#include <stdint.h>
#include <stdbool.h>
#endif
#include "../include/usb_cmd.h" #include "../include/usb_cmd.h"
// prox.cpp // prox.cpp
void ReceiveCommand(UsbCommand *c); void ReceiveCommand(UsbCommand *c);
BOOL ReceiveCommandPoll(UsbCommand *c); bool ReceiveCommandPoll(UsbCommand *c);
void SendCommand(UsbCommand *c, BOOL wantAck); void SendCommand(UsbCommand *c, bool);
void wait_for_response(uint32_t command_type);
// gui.cpp // gui.cpp
void ShowGui(); void ShowGui(void);
void HideGraphWindow(void); void HideGraphWindow(void);
void ShowGraphWindow(void); void ShowGraphWindow(void);
void RepaintGraphWindow(void); void RepaintGraphWindow(void);
@ -24,7 +33,7 @@ extern int offline;
// command.cpp // command.cpp
static void CmdBuffClear(char *str); static void CmdBuffClear(char *str);
static void GetFromBigBuf(BYTE *dest, int bytes); static void GetFromBigBuf(uint8_t *dest, int bytes);
static void CmdReset(char *str); static void CmdReset(char *str);
static void CmdQuit(char *str); static void CmdQuit(char *str);
static void CmdEM410xread(char *str); static void CmdEM410xread(char *str);
@ -61,7 +70,7 @@ static void CmdHisamples(char *str);
static int CmdHisamplest(char *str, int nrlow); static int CmdHisamplest(char *str, int nrlow);
static void CmdHexsamples(char *str); static void CmdHexsamples(char *str);
static void CmdHisampless(char *str); static void CmdHisampless(char *str);
static WORD Iso15693Crc(BYTE *v, int n); static uint16_t Iso15693Crc(uint8_t *v, int n);
static void CmdHi14bdemod(char *str); static void CmdHi14bdemod(char *str);
static void CmdHi14list(char *str); static void CmdHi14list(char *str);
static void CmdHi14alist(char *str); static void CmdHi14alist(char *str);

View file

@ -6,7 +6,7 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "translate.h" //#include "translate.h"
#include "prox.h" #include "prox.h"
#include "proxmark3.h" #include "proxmark3.h"

View file

@ -1,11 +1,12 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h> #include <unistd.h>
#include <usb.h> #include <usb.h>
#include <strings.h> #include <strings.h>
#include <errno.h> #include <errno.h>
#include "translate.h"
#include "prox.h" #include "prox.h"
#include "proxmark3.h" #include "proxmark3.h"
@ -14,7 +15,7 @@ static unsigned int claimed_iface = 0;
unsigned char return_on_error = 0; unsigned char return_on_error = 0;
unsigned char error_occured = 0; unsigned char error_occured = 0;
void SendCommand(UsbCommand *c, BOOL wantAck) { void SendCommand(UsbCommand *c, bool wantAck) {
int ret; int ret;
#if 0 #if 0

View file

@ -7,88 +7,111 @@
#ifndef __USB_CMD_H #ifndef __USB_CMD_H
#define __USB_CMD_H #define __USB_CMD_H
#ifdef _MSC_VER
typedef DWORD uint32_t;
typedef BYTE uint8_t;
#define PACKED
// stuff
#else
#include <stdint.h>
#include <stdbool.h>
#define PACKED __attribute__((packed))
#endif
typedef struct { typedef struct {
DWORD cmd; uint32_t cmd;
DWORD ext1; uint32_t arg[3];
DWORD ext2;
DWORD ext3;
union { union {
BYTE asBytes[48]; uint8_t asBytes[48];
DWORD asDwords[12]; uint32_t asDwords[12];
} d; } d;
} UsbCommand; } PACKED UsbCommand;
// For the bootloader // For the bootloader
#define CMD_DEVICE_INFO 0x0000 #define CMD_DEVICE_INFO 0x0000
#define CMD_SETUP_WRITE 0x0001 #define CMD_SETUP_WRITE 0x0001
#define CMD_FINISH_WRITE 0x0003 #define CMD_FINISH_WRITE 0x0003
#define CMD_HARDWARE_RESET 0x0004 #define CMD_HARDWARE_RESET 0x0004
#define CMD_START_FLASH 0x0005 #define CMD_START_FLASH 0x0005
#define CMD_NACK 0x00fe #define CMD_NACK 0x00fe
#define CMD_ACK 0x00ff #define CMD_ACK 0x00ff
// For general mucking around // For general mucking around
#define CMD_DEBUG_PRINT_STRING 0x0100 #define CMD_DEBUG_PRINT_STRING 0x0100
#define CMD_DEBUG_PRINT_INTEGERS 0x0101 #define CMD_DEBUG_PRINT_INTEGERS 0x0101
#define CMD_DEBUG_PRINT_BYTES 0x0102 #define CMD_DEBUG_PRINT_BYTES 0x0102
#define CMD_LCD_RESET 0x0103 #define CMD_LCD_RESET 0x0103
#define CMD_LCD 0x0104 #define CMD_LCD 0x0104
#define CMD_BUFF_CLEAR 0x0105 #define CMD_BUFF_CLEAR 0x0105
#define CMD_READ_MEM 0x0106 #define CMD_READ_MEM 0x0106
#define CMD_VERSION 0x0107 #define CMD_VERSION 0x0107
// For low-frequency tags // For low-frequency tags
#define CMD_READ_TI_TYPE 0x0202 #define CMD_READ_TI_TYPE 0x0202
#define CMD_WRITE_TI_TYPE 0x0203 #define CMD_WRITE_TI_TYPE 0x0203
#define CMD_DOWNLOADED_RAW_BITS_TI_TYPE 0x0204 #define CMD_DOWNLOADED_RAW_BITS_TI_TYPE 0x0204
#define CMD_ACQUIRE_RAW_ADC_SAMPLES_125K 0x0205 #define CMD_ACQUIRE_RAW_ADC_SAMPLES_125K 0x0205
#define CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K 0x0206 #define CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K 0x0206
#define CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K 0x0207 #define CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K 0x0207
#define CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K 0x0208 #define CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K 0x0208
#define CMD_DOWNLOADED_SIM_SAMPLES_125K 0x0209 #define CMD_DOWNLOADED_SIM_SAMPLES_125K 0x0209
#define CMD_SIMULATE_TAG_125K 0x020A #define CMD_SIMULATE_TAG_125K 0x020A
#define CMD_HID_DEMOD_FSK 0x020B #define CMD_HID_DEMOD_FSK 0x020B
#define CMD_HID_SIM_TAG 0x020C #define CMD_HID_SIM_TAG 0x020C
#define CMD_SET_LF_DIVISOR 0x020D #define CMD_SET_LF_DIVISOR 0x020D
#define CMD_LF_SIMULATE_BIDIR 0x020E #define CMD_LF_SIMULATE_BIDIR 0x020E
#define CMD_SET_ADC_MUX 0x020F #define CMD_SET_ADC_MUX 0x020F
/* CMD_SET_ADC_MUX: ext1 is 0 for lopkd, 1 for loraw, 2 for hipkd, 3 for hiraw */ /* CMD_SET_ADC_MUX: ext1 is 0 for lopkd, 1 for loraw, 2 for hipkd, 3 for hiraw */
// For the 13.56 MHz tags // For the 13.56 MHz tags
#define CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_15693 0x0300 #define CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_15693 0x0300
#define CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443 0x0301 #define CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443 0x0301
#define CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM 0x0302 #define CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM 0x0302
#define CMD_READ_SRI512_TAG 0x0303 #define CMD_READ_SRI512_TAG 0x0303
#define CMD_READ_SRIX4K_TAG 0x0304 #define CMD_READ_SRIX4K_TAG 0x0304
#define CMD_READER_ISO_15693 0x0310 #define CMD_READER_ISO_15693 0x0310
#define CMD_SIMTAG_ISO_15693 0x0311 #define CMD_SIMTAG_ISO_15693 0x0311
#define CMD_SIMULATE_TAG_HF_LISTEN 0x0380 #define CMD_SIMULATE_TAG_HF_LISTEN 0x0380
#define CMD_SIMULATE_TAG_ISO_14443 0x0381 #define CMD_SIMULATE_TAG_ISO_14443 0x0381
#define CMD_SNOOP_ISO_14443 0x0382 #define CMD_SNOOP_ISO_14443 0x0382
#define CMD_SNOOP_ISO_14443a 0x0383 #define CMD_SNOOP_ISO_14443a 0x0383
#define CMD_SIMULATE_TAG_ISO_14443a 0x0384 #define CMD_SIMULATE_TAG_ISO_14443a 0x0384
#define CMD_READER_ISO_14443a 0x0385 #define CMD_READER_ISO_14443a 0x0385
#define CMD_SIMULATE_MIFARE_CARD 0x0386 #define CMD_SIMULATE_MIFARE_CARD 0x0386
#define CMD_SIMULATE_TAG_LEGIC_RF 0x387 #define CMD_SIMULATE_TAG_LEGIC_RF 0x0387
#define CMD_READER_LEGIC_RF 0x388 #define CMD_READER_LEGIC_RF 0x0388
// For measurements of the antenna tuning // For measurements of the antenna tuning
#define CMD_MEASURE_ANTENNA_TUNING 0x0400 #define CMD_MEASURE_ANTENNA_TUNING 0x0400
#define CMD_MEASURED_ANTENNA_TUNING 0x0401 #define CMD_MEASURED_ANTENNA_TUNING 0x0401
#define CMD_LISTEN_READER_FIELD 0x0402 #define CMD_LISTEN_READER_FIELD 0x0402
// For direct FPGA control // For direct FPGA control
#define CMD_FPGA_MAJOR_MODE_OFF 0x0500 #define CMD_FPGA_MAJOR_MODE_OFF 0x0500
// CMD_DEVICE_INFO response packet has flags in ext1, flag definitions: #define CMD_UNKNOWN 0xFFFF
#define DEVICE_INFO_FLAG_BOOTROM_PRESENT (1<<0) /* Whether a bootloader that understands the common_area is present */
#define DEVICE_INFO_FLAG_OSIMAGE_PRESENT (1<<1) /* Whether a osimage that understands the common_area is present */
#define DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM (1<<2) /* Set if the bootloader is currently executing */
#define DEVICE_INFO_FLAG_CURRENT_MODE_OS (1<<3) /* Set if the OS is currently executing */
#define DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH (1<<4) /* Set if this device understands the extend start flash command */
// CMD_START_FLASH may have three arguments: start of area to flash, end of area to flash, optional magic defined below // CMD_DEVICE_INFO response packet has flags in arg[0], flag definitions:
#define START_FLASH_MAGIC 0x54494f44 /* The bootrom will not allow to overwrite itself unless this magic is given as third parameter */ /* Whether a bootloader that understands the common_area is present */
#define DEVICE_INFO_FLAG_BOOTROM_PRESENT (1<<0)
/* Whether a osimage that understands the common_area is present */
#define DEVICE_INFO_FLAG_OSIMAGE_PRESENT (1<<1)
/* Set if the bootloader is currently executing */
#define DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM (1<<2)
/* Set if the OS is currently executing */
#define DEVICE_INFO_FLAG_CURRENT_MODE_OS (1<<3)
/* Set if this device understands the extend start flash command */
#define DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH (1<<4)
/* CMD_START_FLASH may have three arguments: start of area to flash,
end of area to flash, optional magic.
The bootrom will not allow to overwrite itself unless this magic
is given as third parameter */
#define START_FLASH_MAGIC 0x54494f44 // 'DOIT'
#endif #endif