major USB update

This commit is contained in:
roel@libnfc.org
2012-12-04 23:39:18 +00:00
parent 8b39fed4e5
commit 902cb3c00b
44 changed files with 649 additions and 513 deletions
+22
View File
@@ -9,6 +9,7 @@
#include "proxmark3.h"
#include "apps.h"
#include "LCD.h"
#include "fonts.h"
void LCDSend(unsigned int data)
{
@@ -128,4 +129,25 @@ void LCDInit(void)
LCDSend(PRAMWR); // Write to display
i=LCD_XRES*LCD_YRES;
while(i--) LCDSend(WHITE);
// test text on different colored backgrounds
LCDString(" The quick brown fox ", (char *)&FONT6x8,1,1+8*0,WHITE ,BLACK );
LCDString(" jumped over the ", (char *)&FONT6x8,1,1+8*1,BLACK ,WHITE );
LCDString(" lazy dog. ", (char *)&FONT6x8,1,1+8*2,YELLOW ,RED );
LCDString(" AaBbCcDdEeFfGgHhIiJj ", (char *)&FONT6x8,1,1+8*3,RED ,GREEN );
LCDString(" KkLlMmNnOoPpQqRrSsTt ", (char *)&FONT6x8,1,1+8*4,MAGENTA,BLUE );
LCDString("UuVvWwXxYyZz0123456789", (char *)&FONT6x8,1,1+8*5,BLUE ,YELLOW);
LCDString("`-=[]_;',./~!@#$%^&*()", (char *)&FONT6x8,1,1+8*6,BLACK ,CYAN );
LCDString(" _+{}|:\\\"<>? ",(char *)&FONT6x8,1,1+8*7,BLUE ,MAGENTA);
// color bands
LCDFill(0, 1+8* 8, 132, 8, BLACK);
LCDFill(0, 1+8* 9, 132, 8, WHITE);
LCDFill(0, 1+8*10, 132, 8, RED);
LCDFill(0, 1+8*11, 132, 8, GREEN);
LCDFill(0, 1+8*12, 132, 8, BLUE);
LCDFill(0, 1+8*13, 132, 8, YELLOW);
LCDFill(0, 1+8*14, 132, 8, CYAN);
LCDFill(0, 1+8*15, 132, 8, MAGENTA);
}
+3 -1
View File
@@ -27,7 +27,9 @@ THUMBSRC = start.c \
appmain.c printf.c \
util.c \
string.c \
usb.c
usb.c \
usb_cdc.c \
cmd.c
# These are to be compiled in ARM mode
ARMSRC = fpgaloader.c \
+88 -83
View File
@@ -10,6 +10,9 @@
// executes.
//-----------------------------------------------------------------------------
#include "usb_cdc.h"
#include "cmd.h"
#include "proxmark3.h"
#include "apps.h"
#include "util.h"
@@ -22,8 +25,7 @@
#include <hitag2.h>
#ifdef WITH_LCD
# include "fonts.h"
# include "LCD.h"
#include "LCD.h"
#endif
#define abs(x) ( ((x)<0) ? -(x) : (x) )
@@ -77,39 +79,41 @@ void ToSendStuffBit(int b)
void DbpString(char *str)
{
/* this holds up stuff unless we're connected to usb */
if (!UsbConnected())
return;
UsbCommand c;
c.cmd = CMD_DEBUG_PRINT_STRING;
c.arg[0] = strlen(str);
if(c.arg[0] > sizeof(c.d.asBytes)) {
c.arg[0] = sizeof(c.d.asBytes);
}
memcpy(c.d.asBytes, str, c.arg[0]);
UsbSendPacket((uint8_t *)&c, sizeof(c));
// TODO fix USB so stupid things like this aren't req'd
SpinDelay(50);
cmd_send(CMD_DEBUG_PRINT_STRING,strlen(str),0,0,(byte_t*)str,strlen(str));
// /* this holds up stuff unless we're connected to usb */
// if (!UsbConnected())
// return;
//
// UsbCommand c;
// c.cmd = CMD_DEBUG_PRINT_STRING;
// c.arg[0] = strlen(str);
// if(c.arg[0] > sizeof(c.d.asBytes)) {
// c.arg[0] = sizeof(c.d.asBytes);
// }
// memcpy(c.d.asBytes, str, c.arg[0]);
//
// UsbSendPacket((uint8_t *)&c, sizeof(c));
// // TODO fix USB so stupid things like this aren't req'd
// SpinDelay(50);
}
#if 0
void DbpIntegers(int x1, int x2, int x3)
{
/* this holds up stuff unless we're connected to usb */
if (!UsbConnected())
return;
UsbCommand c;
c.cmd = CMD_DEBUG_PRINT_INTEGERS;
c.arg[0] = x1;
c.arg[1] = x2;
c.arg[2] = x3;
UsbSendPacket((uint8_t *)&c, sizeof(c));
// XXX
SpinDelay(50);
cmd_send(CMD_DEBUG_PRINT_INTEGERS,x1,x2,x3,0,0);
// /* this holds up stuff unless we're connected to usb */
// if (!UsbConnected())
// return;
//
// UsbCommand c;
// c.cmd = CMD_DEBUG_PRINT_INTEGERS;
// c.arg[0] = x1;
// c.arg[1] = x2;
// c.arg[2] = x3;
//
// UsbSendPacket((uint8_t *)&c, sizeof(c));
// // XXX
// SpinDelay(50);
}
#endif
@@ -194,7 +198,7 @@ void MeasureAntennaTuning(void)
int i, adcval = 0, peak = 0, peakv = 0, peakf = 0; //ptr = 0
int vLf125 = 0, vLf134 = 0, vHf = 0; // in mV
UsbCommand c;
// UsbCommand c;
LED_B_ON();
DbpString("Measuring antenna characteristics, please wait...");
@@ -237,14 +241,14 @@ void MeasureAntennaTuning(void)
// can measure voltages up to 33000 mV
vHf = (33000 * AvgAdc(ADC_CHAN_HF)) >> 10;
c.cmd = CMD_MEASURED_ANTENNA_TUNING;
c.arg[0] = (vLf125 << 0) | (vLf134 << 16);
c.arg[1] = vHf;
c.arg[2] = peakf | (peakv << 16);
// c.cmd = CMD_MEASURED_ANTENNA_TUNING;
// c.arg[0] = (vLf125 << 0) | (vLf134 << 16);
// c.arg[1] = vHf;
// c.arg[2] = peakf | (peakv << 16);
DbpString("Measuring complete, sending report back to host");
UsbSendPacket((uint8_t *)&c, sizeof(c));
cmd_send(CMD_MEASURED_ANTENNA_TUNING,vLf125|(vLf134<<16),vHf,peakf|(peakv<<16),0,0);
// UsbSendPacket((uint8_t *)&c, sizeof(c));
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
LED_A_OFF();
LED_B_OFF();
@@ -613,14 +617,14 @@ void ListenReaderField(int limit)
void UsbPacketReceived(uint8_t *packet, int len)
{
UsbCommand *c = (UsbCommand *)packet;
UsbCommand ack;
ack.cmd = CMD_ACK;
// Dbprintf("received %d bytes, with command: 0x%04x and args: %d %d %d",len,c->cmd,c->arg[0],c->arg[1],c->arg[2]);
switch(c->cmd) {
#ifdef WITH_LF
case CMD_ACQUIRE_RAW_ADC_SAMPLES_125K:
AcquireRawAdcSamples125k(c->arg[0]);
UsbSendPacket((uint8_t*)&ack, sizeof(ack));
cmd_send(CMD_ACK,0,0,0,0,0);
break;
case CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K:
ModThenAcquireRawAdcSamples125k(c->arg[0],c->arg[1],c->arg[2],c->d.asBytes);
@@ -736,13 +740,13 @@ void UsbPacketReceived(uint8_t *packet, int len)
SnoopIso14443a(c->arg[0]);
break;
case CMD_READER_ISO_14443a:
ReaderIso14443a(c, &ack);
ReaderIso14443a(c);
break;
case CMD_SIMULATE_TAG_ISO_14443a:
SimulateIso14443aTag(c->arg[0], c->arg[1], c->arg[2]); // ## Simulate iso14443a tag - pass tag type & UID
break;
case CMD_EPA_PACE_COLLECT_NONCE:
EPA_PACE_Collect_Nonce(c, &ack);
EPA_PACE_Collect_Nonce(c);
break;
case CMD_READER_MIFARE:
@@ -838,16 +842,26 @@ void UsbPacketReceived(uint8_t *packet, int len)
break;
case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K: {
UsbCommand n;
if(c->cmd == CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K) {
n.cmd = CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K;
} else {
n.cmd = CMD_DOWNLOADED_RAW_BITS_TI_TYPE;
}
n.arg[0] = c->arg[0];
memcpy(n.d.asDwords, BigBuf+c->arg[0], 12*sizeof(uint32_t));
LED_B_ON();
UsbSendPacket((uint8_t *)&n, sizeof(n));
// UsbCommand n;
// if(c->cmd == CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K) {
// n.cmd = CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K;
// } else {
// n.cmd = CMD_DOWNLOADED_RAW_BITS_TI_TYPE;
// }
// n.arg[0] = c->arg[0];
// memcpy(n.d.asBytes, BigBuf+c->arg[0], 48); // 12*sizeof(uint32_t)
// LED_B_ON();
// usb_write((uint8_t *)&n, sizeof(n));
// UsbSendPacket((uint8_t *)&n, sizeof(n));
// LED_B_OFF();
LED_B_ON();
for(size_t i=0; i<c->arg[1]; i += USB_CMD_DATA_SIZE) {
size_t len = MIN((c->arg[1] - i),USB_CMD_DATA_SIZE);
cmd_send(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K,i,len,0,((byte_t*)BigBuf)+c->arg[0]+i,len);
}
// Trigger a finish downloading signal with an ACK frame
cmd_send(CMD_ACK,0,0,0,0,0);
LED_B_OFF();
} break;
@@ -855,7 +869,8 @@ void UsbPacketReceived(uint8_t *packet, int len)
uint8_t *b = (uint8_t *)BigBuf;
memcpy(b+c->arg[0], c->d.asBytes, 48);
//Dbprintf("copied 48 bytes to %i",b+c->arg[0]);
UsbSendPacket((uint8_t*)&ack, sizeof(ack));
// UsbSendPacket((uint8_t*)&ack, sizeof(ack));
cmd_send(CMD_ACK,0,0,0,0,0);
} break;
case CMD_READ_MEM:
@@ -909,11 +924,10 @@ void UsbPacketReceived(uint8_t *packet, int len)
} break;
case CMD_DEVICE_INFO: {
UsbCommand c;
c.cmd = CMD_DEVICE_INFO;
c.arg[0] = DEVICE_INFO_FLAG_OSIMAGE_PRESENT | DEVICE_INFO_FLAG_CURRENT_MODE_OS;
if(common_area.flags.bootrom_present) c.arg[0] |= DEVICE_INFO_FLAG_BOOTROM_PRESENT;
UsbSendPacket((uint8_t*)&c, sizeof(c));
uint32_t dev_info = DEVICE_INFO_FLAG_OSIMAGE_PRESENT | DEVICE_INFO_FLAG_CURRENT_MODE_OS;
if(common_area.flags.bootrom_present) dev_info |= DEVICE_INFO_FLAG_BOOTROM_PRESENT;
// UsbSendPacket((uint8_t*)&c, sizeof(c));
cmd_send(CMD_DEVICE_INFO,dev_info,0,0,0,0);
} break;
default: {
@@ -939,7 +953,10 @@ void __attribute__((noreturn)) AppMain(void)
LED_B_OFF();
LED_A_OFF();
UsbStart();
// Init USB device
usb_enable();
UsbStart();
// UsbStart();
// The FPGA gets its clock from us from PCK0 output, so set that up.
AT91C_BASE_PIOA->PIO_BSR = GPIO_PCK0;
@@ -959,35 +976,23 @@ void __attribute__((noreturn)) AppMain(void)
FpgaDownloadAndGo();
StartTickCount();
#ifdef WITH_LCD
LCDInit();
// test text on different colored backgrounds
LCDString(" The quick brown fox ", (char *)&FONT6x8,1,1+8*0,WHITE ,BLACK );
LCDString(" jumped over the ", (char *)&FONT6x8,1,1+8*1,BLACK ,WHITE );
LCDString(" lazy dog. ", (char *)&FONT6x8,1,1+8*2,YELLOW ,RED );
LCDString(" AaBbCcDdEeFfGgHhIiJj ", (char *)&FONT6x8,1,1+8*3,RED ,GREEN );
LCDString(" KkLlMmNnOoPpQqRrSsTt ", (char *)&FONT6x8,1,1+8*4,MAGENTA,BLUE );
LCDString("UuVvWwXxYyZz0123456789", (char *)&FONT6x8,1,1+8*5,BLUE ,YELLOW);
LCDString("`-=[]_;',./~!@#$%^&*()", (char *)&FONT6x8,1,1+8*6,BLACK ,CYAN );
LCDString(" _+{}|:\\\"<>? ",(char *)&FONT6x8,1,1+8*7,BLUE ,MAGENTA);
// color bands
LCDFill(0, 1+8* 8, 132, 8, BLACK);
LCDFill(0, 1+8* 9, 132, 8, WHITE);
LCDFill(0, 1+8*10, 132, 8, RED);
LCDFill(0, 1+8*11, 132, 8, GREEN);
LCDFill(0, 1+8*12, 132, 8, BLUE);
LCDFill(0, 1+8*13, 132, 8, YELLOW);
LCDFill(0, 1+8*14, 132, 8, CYAN);
LCDFill(0, 1+8*15, 132, 8, MAGENTA);
#endif
byte_t rx[sizeof(UsbCommand)];
size_t rx_len;
for(;;) {
UsbPoll(FALSE);
if (usb_poll()) {
rx_len = usb_read(rx,sizeof(UsbCommand));
if (rx_len) {
UsbPacketReceived(rx,rx_len);
}
}
// UsbPoll(FALSE);
WDT_HIT();
#ifdef WITH_LF
+6 -5
View File
@@ -16,6 +16,7 @@
#include <stddef.h>
#include "common.h"
#include "hitag2.h"
#include "mifare.h"
// The large multi-purpose buffer, typically used to hold A/D samples,
// maybe processed in some way.
@@ -133,17 +134,17 @@ void RAMFUNC SnoopIso14443(void);
/// iso14443a.h
void RAMFUNC SnoopIso14443a(uint8_t param);
void SimulateIso14443aTag(int tagType, int uid_1st, int uid_2nd); // ## simulate iso14443a tag
void ReaderIso14443a(UsbCommand * c, UsbCommand * ack);
void ReaderIso14443a(UsbCommand * c);
// Also used in iclass.c
int RAMFUNC LogTrace(const uint8_t * btBytes, int iLen, int iSamples, uint32_t dwParity, int bReader);
uint32_t GetParity(const uint8_t * pbtCmd, int iLen);
void iso14a_set_trigger(int enable);
void iso14a_clear_trace(void);
void iso14a_set_tracing(int enable);
void iso14a_set_trigger(bool enable);
void iso14a_clear_trace();
void iso14a_set_tracing(bool enable);
void RAMFUNC SniffMifare(uint8_t param);
/// epa.h
void EPA_PACE_Collect_Nonce(UsbCommand * c, UsbCommand * ack);
void EPA_PACE_Collect_Nonce(UsbCommand * c);
// mifarecmd.h
void ReaderMifare(uint32_t parameter);
+23 -21
View File
@@ -12,8 +12,8 @@
//-----------------------------------------------------------------------------
#include "iso14443a.h"
#include "epa.h"
#include "cmd.h"
// Protocol and Parameter Selection Request
// use regular (1x) speed in both directions
@@ -211,24 +211,25 @@ int EPA_Read_CardAccess(uint8_t *buffer, size_t max_length)
// Abort helper function for EPA_PACE_Collect_Nonce
// sets relevant data in ack, sends the response
//-----------------------------------------------------------------------------
static void EPA_PACE_Collect_Nonce_Abort(UsbCommand *ack, uint8_t step, int func_return)
static void EPA_PACE_Collect_Nonce_Abort(uint8_t step, int func_return)
{
// step in which the failure occured
ack->arg[0] = step;
// last return code
ack->arg[1] = func_return;
// // step in which the failure occured
// ack->arg[0] = step;
// // last return code
// ack->arg[1] = func_return;
// power down the field
EPA_Finish();
// send the USB packet
UsbSendPacket((void *)ack, sizeof(UsbCommand));
cmd_send(CMD_ACK,step,func_return,0,0,0);
//UsbSendPacket((void *)ack, sizeof(UsbCommand));
}
//-----------------------------------------------------------------------------
// Acquire one encrypted PACE nonce
//-----------------------------------------------------------------------------
void EPA_PACE_Collect_Nonce(UsbCommand *c, UsbCommand *ack)
void EPA_PACE_Collect_Nonce(UsbCommand *c)
{
/*
* ack layout:
@@ -244,14 +245,14 @@ void EPA_PACE_Collect_Nonce(UsbCommand *c, UsbCommand *ack)
// return value of a function
int func_return;
// initialize ack with 0s
memset(ack->arg, 0, 12);
memset(ack->d.asBytes, 0, 48);
// // initialize ack with 0s
// memset(ack->arg, 0, 12);
// memset(ack->d.asBytes, 0, 48);
// set up communication
func_return = EPA_Setup();
if (func_return != 0) {
EPA_PACE_Collect_Nonce_Abort(ack, 1, func_return);
EPA_PACE_Collect_Nonce_Abort(1, func_return);
return;
}
@@ -264,7 +265,7 @@ void EPA_PACE_Collect_Nonce(UsbCommand *c, UsbCommand *ack)
int card_access_length = EPA_Read_CardAccess(card_access, 256);
// the response has to be at least this big to hold the OID
if (card_access_length < 18) {
EPA_PACE_Collect_Nonce_Abort(ack, 2, card_access_length);
EPA_PACE_Collect_Nonce_Abort(2, card_access_length);
return;
}
@@ -275,7 +276,7 @@ void EPA_PACE_Collect_Nonce(UsbCommand *c, UsbCommand *ack)
card_access_length,
&pace_version_info);
if (func_return != 0 || pace_version_info.version == 0) {
EPA_PACE_Collect_Nonce_Abort(ack, 3, func_return);
EPA_PACE_Collect_Nonce_Abort(3, func_return);
return;
}
@@ -290,17 +291,18 @@ void EPA_PACE_Collect_Nonce(UsbCommand *c, UsbCommand *ack)
// check if the command succeeded
if (func_return < 0)
{
EPA_PACE_Collect_Nonce_Abort(ack, 4, func_return);
EPA_PACE_Collect_Nonce_Abort(4, func_return);
return;
}
// all done, return
EPA_Finish();
// save received information
ack->arg[1] = func_return;
memcpy(ack->d.asBytes, nonce, func_return);
// all done, return
EPA_Finish();
UsbSendPacket((void *)ack, sizeof(UsbCommand));
// ack->arg[1] = func_return;
// memcpy(ack->d.asBytes, nonce, func_return);
// UsbSendPacket((void *)ack, sizeof(UsbCommand));
cmd_send(CMD_ACK,0,func_return,0,nonce,func_return);
}
//-----------------------------------------------------------------------------
+2 -4
View File
@@ -116,13 +116,11 @@ void FpgaSetupSsc(void)
// 8 bits per transfer, no loopback, MSB first, 1 transfer per sync
// pulse, no output sync, start on positive-going edge of sync
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) |
AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
// clock comes from TK pin, no clock output, outputs change on falling
// edge of TK, start on rising edge of TF
AT91C_BASE_SSC->SSC_TCMR = SSC_CLOCK_MODE_SELECT(2) |
SSC_CLOCK_MODE_START(5);
AT91C_BASE_SSC->SSC_TCMR = SSC_CLOCK_MODE_SELECT(2) | SSC_CLOCK_MODE_START(5);
// tx framing is the same as the rx framing
AT91C_BASE_SSC->SSC_TFMR = AT91C_BASE_SSC->SSC_RFMR;
+39 -25
View File
@@ -14,6 +14,7 @@
#include "apps.h"
#include "util.h"
#include "string.h"
#include "cmd.h"
#include "iso14443crc.h"
#include "iso14443a.h"
@@ -64,16 +65,16 @@ const uint8_t OddByteParity[256] = {
};
void iso14a_set_trigger(int enable) {
void iso14a_set_trigger(bool enable) {
trigger = enable;
}
void iso14a_clear_trace(void) {
memset(trace, 0x44, TRACE_SIZE);
void iso14a_clear_trace() {
memset(trace, 0x44, TRACE_SIZE);
traceLen = 0;
}
void iso14a_set_tracing(int enable) {
void iso14a_set_tracing(bool enable) {
tracing = enable;
}
@@ -1641,7 +1642,7 @@ int iso14443a_select_card(uint8_t * uid_ptr, iso14a_card_select_t * resp_data, u
uint8_t sel_uid[] = { 0x93,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
uint8_t rats[] = { 0xE0,0x80,0x00,0x00 }; // FSD=256, FSDI=8, CID=0
uint8_t* resp = (((uint8_t *)BigBuf) + 3560); // was 3560 - tied to other size changes
uint8_t* resp = (((uint8_t *)BigBuf) + FREE_BUFFER_OFFSET); // was 3560 - tied to other size changes
uint8_t sak = 0x04; // cascade uid
int cascade_level = 0;
@@ -1649,13 +1650,14 @@ int iso14443a_select_card(uint8_t * uid_ptr, iso14a_card_select_t * resp_data, u
int len;
// clear uid
memset(uid_ptr, 0, 8);
memset(uid_ptr, 0, 12);
// Broadcast for a card, WUPA (0x52) will force response from all cards in the field
ReaderTransmitShort(wupa);
// Receive the ATQA
if(!ReaderReceive(resp)) return 0;
// Dbprintf("atqa: %02x %02x",resp[0],resp[1]);
if(resp_data)
memcpy(resp_data->atqa, resp, 2);
@@ -1670,6 +1672,8 @@ int iso14443a_select_card(uint8_t * uid_ptr, iso14a_card_select_t * resp_data, u
// SELECT_ALL
ReaderTransmit(sel_all,sizeof(sel_all));
if (!ReaderReceive(resp)) return 0;
// Dbprintf("uid: %02x %02x %02x %02x",resp[0],resp[1],resp[2],resp[3]);
if(uid_ptr) memcpy(uid_ptr + cascade_level*4, resp, 4);
// calculate crypto UID
@@ -1715,13 +1719,13 @@ int iso14443a_select_card(uint8_t * uid_ptr, iso14a_card_select_t * resp_data, u
}
void iso14443a_setup() {
// Setup SSC
FpgaSetupSsc();
// Set up the synchronous serial port
FpgaSetupSsc();
// Start from off (no field generated)
// Signal field is off with the appropriate LED
LED_D_OFF();
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
SpinDelay(200);
SpinDelay(50);
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
@@ -1729,7 +1733,7 @@ void iso14443a_setup() {
// Signal field is on with the appropriate LED
LED_D_ON();
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_MOD);
SpinDelay(200);
SpinDelay(50);
iso14a_timeout = 2048; //default
}
@@ -1765,18 +1769,24 @@ int iso14_apdu(uint8_t * cmd, size_t cmd_len, void * data) {
// Read an ISO 14443a tag. Send out commands and store answers.
//
//-----------------------------------------------------------------------------
void ReaderIso14443a(UsbCommand * c, UsbCommand * ack)
void ReaderIso14443a(UsbCommand * c)
{
iso14a_command_t param = c->arg[0];
uint8_t * cmd = c->d.asBytes;
size_t len = c->arg[1];
uint32_t arg0;
byte_t buf[48];
iso14a_clear_trace();
iso14a_set_tracing(true);
if(param & ISO14A_REQUEST_TRIGGER) iso14a_set_trigger(1);
if(param & ISO14A_CONNECT) {
iso14443a_setup();
ack->arg[0] = iso14443a_select_card(ack->d.asBytes, (iso14a_card_select_t *) (ack->d.asBytes+12), NULL);
UsbSendPacket((void *)ack, sizeof(UsbCommand));
arg0 = iso14443a_select_card(buf, (iso14a_card_select_t *)(buf+12), NULL);
cmd_send(CMD_ACK,arg0,0,0,buf,48);
// UsbSendPacket((void *)ack, sizeof(UsbCommand));
}
if(param & ISO14A_SET_TIMEOUT) {
@@ -1788,8 +1798,9 @@ void ReaderIso14443a(UsbCommand * c, UsbCommand * ack)
}
if(param & ISO14A_APDU) {
ack->arg[0] = iso14_apdu(cmd, len, ack->d.asBytes);
UsbSendPacket((void *)ack, sizeof(UsbCommand));
arg0 = iso14_apdu(cmd, len, buf);
cmd_send(CMD_ACK,arg0,0,0,buf,48);
// UsbSendPacket((void *)ack, sizeof(UsbCommand));
}
if(param & ISO14A_RAW) {
@@ -1798,8 +1809,9 @@ void ReaderIso14443a(UsbCommand * c, UsbCommand * ack)
len += 2;
}
ReaderTransmit(cmd,len);
ack->arg[0] = ReaderReceive(ack->d.asBytes);
UsbSendPacket((void *)ack, sizeof(UsbCommand));
arg0 = ReaderReceive(buf);
// UsbSendPacket((void *)ack, sizeof(UsbCommand));
cmd_send(CMD_ACK,arg0,0,0,buf,48);
}
if(param & ISO14A_REQUEST_TRIGGER) iso14a_set_trigger(0);
@@ -1821,7 +1833,7 @@ void ReaderMifare(uint32_t parameter)
uint8_t mf_auth[] = { 0x60,0x00,0xf5,0x7b };
uint8_t mf_nr_ar[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
uint8_t* receivedAnswer = (((uint8_t *)BigBuf) + 3560); // was 3560 - tied to other size changes
uint8_t* receivedAnswer = (((uint8_t *)BigBuf) + FREE_BUFFER_OFFSET); // was 3560 - tied to other size changes
traceLen = 0;
tracing = false;
@@ -1918,14 +1930,16 @@ void ReaderMifare(uint32_t parameter)
LogTrace(par_list, 8, 0, GetParity(par_list, 8), TRUE);
LogTrace(ks_list, 8, 0, GetParity(ks_list, 8), TRUE);
UsbCommand ack = {CMD_ACK, {isOK, 0, 0}};
memcpy(ack.d.asBytes + 0, uid, 4);
memcpy(ack.d.asBytes + 4, nt, 4);
memcpy(ack.d.asBytes + 8, par_list, 8);
memcpy(ack.d.asBytes + 16, ks_list, 8);
byte_t buf[48];
// UsbCommand ack = {CMD_ACK, {isOK, 0, 0}};
memcpy(buf + 0, uid, 4);
memcpy(buf + 4, nt, 4);
memcpy(buf + 8, par_list, 8);
memcpy(buf + 16, ks_list, 8);
LED_B_ON();
UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));
cmd_send(CMD_ACK,isOK,0,0,buf,48);
// UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));
LED_B_OFF();
// Thats it...
+3 -3
View File
@@ -91,10 +91,10 @@ extern int ReaderReceivePar(uint8_t* receivedAnswer, uint32_t * parptr);
extern void iso14443a_setup();
extern int iso14_apdu(uint8_t * cmd, size_t cmd_len, void * data);
extern int iso14443a_select_card(uint8_t * uid_ptr, iso14a_card_select_t * resp_data, uint32_t * cuid_ptr);
extern void iso14a_set_trigger(int enable);
extern void iso14a_set_trigger(bool enable);
extern void iso14a_set_timeout(uint32_t timeout);
extern void iso14a_clear_tracelen(void);
extern void iso14a_set_tracing(int enable);
extern void iso14a_clear_tracelen();
extern void iso14a_set_tracing(bool enable);
#endif /* __ISO14443A_H */
+7 -6
View File
@@ -63,7 +63,7 @@
#include "apps.h"
#include "string.h"
#include "iso15693tools.h"
#include "cmd.h"
#define arraylen(x) (sizeof(x)/sizeof((x)[0]))
@@ -1260,7 +1260,7 @@ void DirectTag15693Command(uint32_t datalen,uint32_t speed, uint32_t recv, uint8
int recvlen=0;
uint8_t *recvbuf=(uint8_t *)BigBuf;
UsbCommand n;
// UsbCommand n;
if (DEBUG) {
Dbprintf("SEND");
@@ -1270,11 +1270,12 @@ void DirectTag15693Command(uint32_t datalen,uint32_t speed, uint32_t recv, uint8
recvlen=SendDataTag(data,datalen,1,speed,(recv?&recvbuf:NULL));
if (recv) {
n.cmd=/* CMD_ISO_15693_COMMAND_DONE */ CMD_ACK;
n.arg[0]=recvlen>48?48:recvlen;
memcpy(n.d.asBytes, recvbuf, 48);
// n.cmd=/* CMD_ISO_15693_COMMAND_DONE */ CMD_ACK;
// n.arg[0]=recvlen>48?48:recvlen;
// memcpy(n.d.asBytes, recvbuf, 48);
LED_B_ON();
UsbSendPacket((uint8_t *)&n, sizeof(n));
cmd_send(CMD_ACK,recvlen>48?48:recvlen,0,0,recvbuf,48);
// UsbSendPacket((uint8_t *)&n, sizeof(n));
LED_B_OFF();
if (DEBUG) {
+1 -1
View File
@@ -166,7 +166,7 @@ int intMfSniffSend() {
FpgaDisableSscDma();
while (pckLen > 0) {
pckSize = min(32, pckLen);
pckSize = MIN(32, pckLen);
UsbCommand ack = {CMD_ACK, {1, pckSize, pckNum}};
memcpy(ack.d.asBytes, trace + traceLen - pckLen, pckSize);
+2 -1
View File
@@ -17,7 +17,8 @@
#define RAMFUNC __attribute((long_call, section(".ramfunc")))
#define BYTEx(x, n) (((x) >> (n * 8)) & 0xff )
#define min(a, b) (((a) > (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define LED_RED 1
#define LED_ORANGE 2
+1 -1
View File
@@ -300,6 +300,6 @@ void BootROM(void)
flash_mode(1);
} else {
// jump to Flash address of the osimage entry point (LSBit set for thumb mode)
asm("bx %0\n" : : "r" ( ((int)&_osimage_entry) | 0x1 ) );
__asm("bx %0\n" : : "r" ( ((int)&_osimage_entry) | 0x1 ) );
}
}
+3 -2
View File
@@ -67,12 +67,13 @@ CMDSRCS = \
cmdlfhitag.c \
cmdlfti.c \
cmdparser.c \
cmdmain.c
cmdmain.c \
uart.c
CMDOBJS = $(CMDSRCS:%.c=$(OBJDIR)/%.o)
RM = rm -f
BINS = proxmark3 snooper cli flasher
BINS = proxmark3 flasher #snooper cli
CLEAN = cli cli.exe flasher flasher.exe proxmark3 proxmark3.exe snooper snooper.exe $(CMDOBJS) $(OBJDIR)/*.o *.o *.moc.cpp
all: $(BINS)
+4 -3
View File
@@ -13,6 +13,7 @@
#include <string.h>
#include <limits.h>
#include "proxusb.h"
#include "proxmark3.h"
#include "data.h"
#include "ui.h"
#include "graph.h"
@@ -158,7 +159,7 @@ int CmdBitsamples(const char *Cmd)
for (int i = 0; i < n; i += 12) {
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};
SendCommand(&c);
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K, NULL);
for (int j = 0; j < 48; j++) {
for (int k = 0; k < 8; k++) {
@@ -418,7 +419,7 @@ int CmdHexsamples(const char *Cmd)
for (int i = offset; i < n+offset; i += 12) {
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};
SendCommand(&c);
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K, NULL);
for (int j = 0; j < 48; j += 8) {
PrintAndLog("%02x %02x %02x %02x %02x %02x %02x %02x",
sample_buf[j+0],
@@ -475,7 +476,7 @@ int CmdSamples(const char *Cmd)
for (int i = 0; i < n; i += 12) {
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};
SendCommand(&c);
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K, NULL);
for (int j = 0; j < 48; j++) {
GraphBuffer[cnt++] = ((int)sample_buf[j]) - 128;
}
+1
View File
@@ -10,6 +10,7 @@
#include <stdio.h>
#include "proxusb.h"
#include "proxmark3.h"
#include "graph.h"
#include "ui.h"
#include "cmdparser.h"
+20 -12
View File
@@ -17,11 +17,13 @@
#include "iso14443crc.h"
#include "data.h"
#include "proxusb.h"
#include "proxmark3.h"
#include "ui.h"
#include "cmdparser.h"
#include "cmdhf14a.h"
#include "common.h"
#include "cmdmain.h"
#include "mifare.h"
static int CmdHelp(const char *Cmd);
@@ -29,6 +31,7 @@ int CmdHF14AList(const char *Cmd)
{
uint8_t got[1920];
GetFromBigBuf(got,sizeof(got),0);
WaitForResponse(CMD_ACK,NULL);
PrintAndLog("recorded activity:");
PrintAndLog(" ETU :rssi: who bytes");
@@ -161,18 +164,21 @@ int CmdHF14AReader(const char *Cmd)
{
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}};
SendCommand(&c);
UsbCommand * resp = WaitForResponse(CMD_ACK);
uint8_t * uid = resp->d.asBytes;
UsbCommand resp;
WaitForResponse(CMD_ACK,&resp);
uint8_t * uid = resp.d.asBytes;
iso14a_card_select_t * card = (iso14a_card_select_t *)(uid + 12);
if(resp->arg[0] == 0) {
if(resp.arg[0] == 0) {
PrintAndLog("iso14443a card select failed");
return 0;
}
PrintAndLog("ATQA : %02x %02x", card->atqa[0], card->atqa[1]);
PrintAndLog(" UID : %s", sprint_hex(uid, 12));
PrintAndLog(" SAK : %02x [%d]", card->sak, resp->arg[0]);
PrintAndLog(" SAK : %02x [%d]", card->sak, resp.arg[0]);
switch (card->sak) {
case 0x00: PrintAndLog(" SAK : NXP MIFARE Ultralight | Ultralight C"); break;
@@ -191,7 +197,7 @@ int CmdHF14AReader(const char *Cmd)
case 0x98: PrintAndLog(" SAK : Gemplus MPCOS"); break;
default: ;
}
if(resp->arg[0] == 1) {
if(resp.arg[0] == 1) {
bool ta1 = 0, tb1 = 0, tc1 = 0;
int pos;
@@ -312,7 +318,7 @@ int CmdHF14AReader(const char *Cmd)
else
PrintAndLog("proprietary non-iso14443a card found, RATS not supported");
return resp->arg[0];
return resp.arg[0];
}
// Collect ISO14443 Type A UIDs
@@ -330,12 +336,15 @@ int CmdHF14ACUIDs(const char *Cmd)
// execute anticollision procedure
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}};
SendCommand(&c);
UsbCommand *resp = WaitForResponse(CMD_ACK);
uint8_t *uid = resp->d.asBytes;
UsbCommand resp;
WaitForResponse(CMD_ACK,&resp);
uint8_t *uid = resp.d.asBytes;
iso14a_card_select_t *card = (iso14a_card_select_t *)(uid + 12);
// check if command failed
if (resp->arg[0] == 0) {
if (resp.arg[0] == 0) {
PrintAndLog("Card select failed.");
} else {
// check if UID is 4 bytes
@@ -472,10 +481,9 @@ static command_t CommandTable[] =
{NULL, NULL, 0, NULL}
};
int CmdHF14A(const char *Cmd)
{
int CmdHF14A(const char *Cmd) {
// flush
while (WaitForResponseTimeout(CMD_ACK, 500) != NULL) ;
WaitForResponseTimeout(CMD_ACK,NULL,100);
// parse
CmdsParse(CommandTable, Cmd);
+1
View File
@@ -15,6 +15,7 @@
#include <stdint.h>
#include "iso14443crc.h"
#include "proxusb.h"
#include "proxmark3.h"
#include "data.h"
#include "graph.h"
#include "ui.h"
+50 -65
View File
@@ -27,6 +27,7 @@
#include <string.h>
#include <stdint.h>
#include "proxusb.h"
#include "proxmark3.h"
#include "data.h"
#include "graph.h"
#include "ui.h"
@@ -94,7 +95,7 @@ const productName uidmapping[] = {
// returns 1 if suceeded
int getUID(uint8_t *buf)
{
UsbCommand *r;
UsbCommand resp;
uint8_t *recv;
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
uint8_t *req=c.d.asBytes;
@@ -111,11 +112,9 @@ int getUID(uint8_t *buf)
SendCommand(&c);
r=WaitForResponseTimeout(CMD_ACK,1000);
if (r!=NULL) {
recv = r->d.asBytes;
if (r->arg[0]>=12 && ISO15_CRC_CHECK==Crc(recv,12)) {
if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
recv = resp.d.asBytes;
if (resp.arg[0]>=12 && ISO15_CRC_CHECK==Crc(recv,12)) {
memcpy(buf,&recv[2],8);
return 1;
}
@@ -292,7 +291,7 @@ int CmdHF15Afi(const char *Cmd)
// Reads all memory pages
int CmdHF15DumpMem(const char*Cmd) {
UsbCommand *r;
UsbCommand resp;
uint8_t uid[8];
uint8_t *recv=NULL;
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
@@ -321,20 +320,18 @@ int CmdHF15DumpMem(const char*Cmd) {
SendCommand(&c);
r=WaitForResponseTimeout(CMD_ACK,1000);
if (r!=NULL) {
recv = r->d.asBytes;
if (ISO15_CRC_CHECK==Crc(recv,r->arg[0])) {
if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
recv = resp.d.asBytes;
if (ISO15_CRC_CHECK==Crc(recv,resp.arg[0])) {
if (!(recv[0] & ISO15_RES_ERROR)) {
retry=0;
*output=0; // reset outputstring
sprintf(output, "Block %2i ",blocknum);
for ( int i=1; i<r->arg[0]-2; i++) { // data in hex
for ( int i=1; i<resp.arg[0]-2; i++) { // data in hex
sprintf(output+strlen(output),"%02hX ",recv[i]);
}
strcat(output," ");
for ( int i=1; i<r->arg[0]-2; i++) { // data in cleaned ascii
for ( int i=1; i<resp.arg[0]-2; i++) { // data in cleaned ascii
sprintf(output+strlen(output),"%c",(recv[i]>31 && recv[i]<127)?recv[i]:'.');
}
PrintAndLog("%s",output);
@@ -346,14 +343,14 @@ int CmdHF15DumpMem(const char*Cmd) {
}
} // else PrintAndLog("crc");
} // else PrintAndLog("r null");
} // retry
if (r && r->arg[0]<3)
PrintAndLog("Lost Connection");
else if (r && ISO15_CRC_CHECK!=Crc(r->d.asBytes,r->arg[0]))
PrintAndLog("CRC Failed");
else
PrintAndLog("Tag returned Error %i: %s",recv[1],TagErrorStr(recv[1]));
// TODO: need fix
// if (resp.arg[0]<3)
// PrintAndLog("Lost Connection");
// else if (ISO15_CRC_CHECK!=Crc(resp.d.asBytes,resp.arg[0]))
// PrintAndLog("CRC Failed");
// else
// PrintAndLog("Tag returned Error %i: %s",recv[1],TagErrorStr(recv[1]));
return 0;
}
@@ -392,7 +389,7 @@ int CmdHF15Help(const char *Cmd)
int CmdHF15CmdInquiry(const char *Cmd)
{
UsbCommand *r;
UsbCommand resp;
uint8_t *recv;
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
uint8_t *req=c.d.asBytes;
@@ -407,15 +404,13 @@ int CmdHF15CmdInquiry(const char *Cmd)
SendCommand(&c);
r=WaitForResponseTimeout(CMD_ACK,1000);
if (r!=NULL) {
if (r->arg[0]>=12) {
recv = r->d.asBytes;
if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
if (resp.arg[0]>=12) {
recv = resp.d.asBytes;
PrintAndLog("UID=%s",sprintUID(NULL,&recv[2]));
PrintAndLog("Tag Info: %s",getTagInfo(&recv[2]));
} else {
PrintAndLog("Response to short, just %i bytes. No tag?\n",r->arg[0]);
PrintAndLog("Response to short, just %i bytes. No tag?\n",resp.arg[0]);
}
} else {
PrintAndLog("timeout.");
@@ -440,7 +435,7 @@ int CmdHF15CmdDebug( const char *cmd) {
int CmdHF15CmdRaw (const char *cmd) {
UsbCommand *r;
UsbCommand resp;
uint8_t *recv;
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
int reply=1;
@@ -515,14 +510,12 @@ int CmdHF15CmdRaw (const char *cmd) {
SendCommand(&c);
if (reply) {
r=WaitForResponseTimeout(CMD_ACK,1000);
if (r!=NULL) {
recv = r->d.asBytes;
PrintAndLog("received %i octets",r->arg[0]);
hexout = (char *)malloc(r->arg[0] * 3 + 1);
if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
recv = resp.d.asBytes;
PrintAndLog("received %i octets",resp.arg[0]);
hexout = (char *)malloc(resp.arg[0] * 3 + 1);
if (hexout != NULL) {
for (int i = 0; i < r->arg[0]; i++) { // data in hex
for (int i = 0; i < resp.arg[0]; i++) { // data in hex
sprintf(&hexout[i * 3], "%02hX ", recv[i]);
}
PrintAndLog("%s", hexout);
@@ -635,7 +628,7 @@ int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd[], int iso15cmdle
* get system information from tag/VICC
*/
int CmdHF15CmdSysinfo(const char *Cmd) {
UsbCommand *r;
UsbCommand resp;
uint8_t *recv;
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
uint8_t *req=c.d.asBytes;
@@ -670,14 +663,12 @@ int CmdHF15CmdSysinfo(const char *Cmd) {
SendCommand(&c);
r=WaitForResponseTimeout(CMD_ACK,1000);
if (r!=NULL && r->arg[0]>2) {
recv = r->d.asBytes;
if (ISO15_CRC_CHECK==Crc(recv,r->arg[0])) {
if (WaitForResponseTimeout(CMD_ACK,&resp,1000) && resp.arg[0]>2) {
recv = resp.d.asBytes;
if (ISO15_CRC_CHECK==Crc(recv,resp.arg[0])) {
if (!(recv[0] & ISO15_RES_ERROR)) {
*output=0; // reset outputstring
for ( i=1; i<r->arg[0]-2; i++) {
for ( i=1; i<resp.arg[0]-2; i++) {
sprintf(output+strlen(output),"%02hX ",recv[i]);
}
strcat(output,"\n\r");
@@ -725,7 +716,7 @@ int CmdHF15CmdSysinfo(const char *Cmd) {
* Read multiple blocks at once (not all tags support this)
*/
int CmdHF15CmdReadmulti(const char *Cmd) {
UsbCommand *r;
UsbCommand resp;
uint8_t *recv;
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
uint8_t *req=c.d.asBytes;
@@ -773,18 +764,16 @@ int CmdHF15CmdReadmulti(const char *Cmd) {
SendCommand(&c);
r=WaitForResponseTimeout(CMD_ACK,1000);
if (r!=NULL && r->arg[0]>2) {
recv = r->d.asBytes;
if (ISO15_CRC_CHECK==Crc(recv,r->arg[0])) {
if (WaitForResponseTimeout(CMD_ACK,&resp,1000) && resp.arg[0]>2) {
recv = resp.d.asBytes;
if (ISO15_CRC_CHECK==Crc(recv,resp.arg[0])) {
if (!(recv[0] & ISO15_RES_ERROR)) {
*output=0; // reset outputstring
for ( int i=1; i<r->arg[0]-2; i++) {
for ( int i=1; i<resp.arg[0]-2; i++) {
sprintf(output+strlen(output),"%02hX ",recv[i]);
}
strcat(output," ");
for ( int i=1; i<r->arg[0]-2; i++) {
for ( int i=1; i<resp.arg[0]-2; i++) {
sprintf(output+strlen(output),"%c",recv[i]>31 && recv[i]<127?recv[i]:'.');
}
PrintAndLog("%s",output);
@@ -806,7 +795,7 @@ int CmdHF15CmdReadmulti(const char *Cmd) {
* Reads a single Block
*/
int CmdHF15CmdRead(const char *Cmd) {
UsbCommand *r;
UsbCommand resp;
uint8_t *recv;
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
uint8_t *req=c.d.asBytes;
@@ -848,19 +837,17 @@ int CmdHF15CmdRead(const char *Cmd) {
SendCommand(&c);
r=WaitForResponseTimeout(CMD_ACK,1000);
if (r!=NULL && r->arg[0]>2) {
recv = r->d.asBytes;
if (ISO15_CRC_CHECK==Crc(recv,r->arg[0])) {
if (WaitForResponseTimeout(CMD_ACK,&resp,1000) && resp.arg[0]>2) {
recv = resp.d.asBytes;
if (ISO15_CRC_CHECK==Crc(recv,resp.arg[0])) {
if (!(recv[0] & ISO15_RES_ERROR)) {
*output=0; // reset outputstring
//sprintf(output, "Block %2i ",blocknum);
for ( int i=1; i<r->arg[0]-2; i++) {
for ( int i=1; i<resp.arg[0]-2; i++) {
sprintf(output+strlen(output),"%02hX ",recv[i]);
}
strcat(output," ");
for ( int i=1; i<r->arg[0]-2; i++) {
for ( int i=1; i<resp.arg[0]-2; i++) {
sprintf(output+strlen(output),"%c",recv[i]>31 && recv[i]<127?recv[i]:'.');
}
PrintAndLog("%s",output);
@@ -883,7 +870,7 @@ int CmdHF15CmdRead(const char *Cmd) {
* Writes a single Block - might run into timeout, even when successful
*/
int CmdHF15CmdWrite(const char *Cmd) {
UsbCommand *r;
UsbCommand resp;
uint8_t *recv;
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
uint8_t *req=c.d.asBytes;
@@ -943,11 +930,9 @@ int CmdHF15CmdWrite(const char *Cmd) {
SendCommand(&c);
r=WaitForResponseTimeout(CMD_ACK,2000);
if (r!=NULL && r->arg[0]>2) {
recv = r->d.asBytes;
if (ISO15_CRC_CHECK==Crc(recv,r->arg[0])) {
if (WaitForResponseTimeout(CMD_ACK,&resp,2000) && resp.arg[0]>2) {
recv = resp.d.asBytes;
if (ISO15_CRC_CHECK==Crc(recv,resp.arg[0])) {
if (!(recv[0] & ISO15_RES_ERROR)) {
PrintAndLog("OK");
} else {
+10 -10
View File
@@ -10,6 +10,7 @@
#include "util.h"
#include "proxusb.h"
#include "proxmark3.h"
#include "ui.h"
#include "cmdparser.h"
#include "common.h"
@@ -42,22 +43,21 @@ int CmdHFEPACollectPACENonces(const char *Cmd)
// execute PACE
UsbCommand c = {CMD_EPA_PACE_COLLECT_NONCE, {(int)m, 0, 0}};
SendCommand(&c);
UsbCommand *resp = WaitForResponse(CMD_ACK);
UsbCommand resp;
WaitForResponse(CMD_ACK,&resp);
// check if command failed
if (resp->arg[0] != 0) {
PrintAndLog("Error in step %d, Return code: %d",
resp->arg[0],
(int)resp->arg[1]);
if (resp.arg[0] != 0) {
PrintAndLog("Error in step %d, Return code: %d",resp.arg[0],(int)resp.arg[1]);
} else {
size_t nonce_length = resp->arg[1];
size_t nonce_length = resp.arg[1];
char *nonce = (char *) malloc(2 * nonce_length + 1);
for(int j = 0; j < nonce_length; j++) {
snprintf(nonce + (2 * j), 3, "%02X", resp->d.asBytes[j]);
snprintf(nonce + (2 * j), 3, "%02X", resp.d.asBytes[j]);
}
// print nonce
PrintAndLog("Length: %d, Nonce: %s",
resp->arg[1], nonce);
PrintAndLog("Length: %d, Nonce: %s",resp.arg[1], nonce);
}
if (i < n - 1) {
sleep(d);
@@ -87,7 +87,7 @@ int CmdHelp(const char *Cmd)
int CmdHFEPA(const char *Cmd)
{
// flush
while (WaitForResponseTimeout(CMD_ACK, 500) != NULL) ;
while (!WaitForResponseTimeout(CMD_ACK,NULL,500));
// parse
CmdsParse(CommandTable, Cmd);
+1
View File
@@ -15,6 +15,7 @@
#include "iso14443crc.h" // Can also be used for iClass, using 0xE012 as CRC-type
#include "data.h"
#include "proxusb.h"
#include "proxmark3.h"
#include "ui.h"
#include "cmdparser.h"
#include "cmdhficlass.h"

Some files were not shown because too many files have changed in this diff Show More