From 4e20973b8da67b3c71c7d12e8fcd8fdd35b3c522 Mon Sep 17 00:00:00 2001 From: Peter Fillmore Date: Sat, 15 Nov 2014 16:31:48 +1100 Subject: [PATCH 1/2] Added "TRACE_BUFFER_SIZE" to reflect actual length of trace buffer to the proxmark client - fixes issue with printing large recorded traces --- client/cmdhf14a.c | 8 ++++---- client/cmdhf14b.c | 8 +++++--- client/cmdhficlass.c | 5 +++-- client/cmdlfhitag.c | 8 +++++--- client/data.h | 4 ++-- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index 39bdcf40..bb209d9d 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -31,7 +31,6 @@ int CmdHF14AList(const char *Cmd) { bool ShowWaitCycles = false; char param = param_getchar(Cmd, 0); - if (param == 'h' || (param != 0 && param != 'f')) { PrintAndLog("List data in trace buffer."); PrintAndLog("Usage: hf 14a list [f]"); @@ -44,7 +43,8 @@ int CmdHF14AList(const char *Cmd) ShowWaitCycles = true; } - uint8_t got[1920]; + //uint8_t got[1920]; + uint8_t got[TRACE_BUFFER_SIZE]; //changed to retrieve actual trace buffer size in apps.h in armsrc GetFromBigBuf(got,sizeof(got),0); WaitForResponse(CMD_ACK,NULL); @@ -62,7 +62,7 @@ int CmdHF14AList(const char *Cmd) uint32_t EndOfTransmissionTimestamp = 0; for (;;) { - if(i >= 1900) { + if(i >= TRACE_BUFFER_SIZE) { break; } @@ -86,7 +86,7 @@ int CmdHF14AList(const char *Cmd) if (len > 100) { break; } - if (i + len >= 1900) { + if (i + len >= TRACE_BUFFER_SIZE) { break; } diff --git a/client/cmdhf14b.c b/client/cmdhf14b.c index c42d54c5..aebc0734 100644 --- a/client/cmdhf14b.c +++ b/client/cmdhf14b.c @@ -145,7 +145,7 @@ demodError: int CmdHF14BList(const char *Cmd) { - uint8_t got[960]; + uint8_t got[TRACE_BUFFER_SIZE]; GetFromBigBuf(got,sizeof(got),0); WaitForResponse(CMD_ACK,NULL); @@ -157,7 +157,8 @@ int CmdHF14BList(const char *Cmd) int prev = -1; for(;;) { - if(i >= 900) { + //if(i >= 900) { + if(i >= TRACE_BUFFER_SIZE) { break; } @@ -176,7 +177,8 @@ int CmdHF14BList(const char *Cmd) if(len > 100) { break; } - if(i + len >= 900) { + //if(i + len >= 900) { + if(i + len >= TRACE_BUFFER_SIZE) { break; } diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index d9af9044..f9e3bb40 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -56,7 +56,8 @@ int CmdHFiClassList(const char *Cmd) return 0; } - uint8_t got[1920]; + //uint8_t got[1920]; + uint8_t got[TRACE_BUFFER_SIZE]; GetFromBigBuf(got,sizeof(got),0); WaitForResponse(CMD_ACK,NULL); @@ -78,7 +79,7 @@ int CmdHFiClassList(const char *Cmd) uint32_t EndOfTransmissionTimestamp = 0; - for( i=0; i < 1900;) + for( i=0; i < TRACE_BUFFER_SIZE;) { //First 32 bits contain // isResponse (1 bit) diff --git a/client/cmdlfhitag.c b/client/cmdlfhitag.c index 32d38aeb..26f8cac6 100644 --- a/client/cmdlfhitag.c +++ b/client/cmdlfhitag.c @@ -30,7 +30,7 @@ size_t nbytes(size_t nbits) { int CmdLFHitagList(const char *Cmd) { - uint8_t got[3000]; + uint8_t got[TRACE_BUFFER_SIZE]; GetFromBigBuf(got,sizeof(got),0); WaitForResponse(CMD_ACK,NULL); @@ -42,7 +42,8 @@ int CmdLFHitagList(const char *Cmd) int prev = -1; for (;;) { - if(i >= 1900) { + //if(i >= 1900) { + if(i >= TRACE_BUFFER_SIZE) { break; } @@ -69,7 +70,8 @@ int CmdLFHitagList(const char *Cmd) if (len > 100) { break; } - if (i + len >= 1900) { + //if (i + len >= 1900) { + if (i + len >= TRACE_BUFFER_SIZE) { break; } diff --git a/client/data.h b/client/data.h index 33ee9d04..70d4ad66 100644 --- a/client/data.h +++ b/client/data.h @@ -12,9 +12,9 @@ #define DATA_H__ #include - +//trace buffer size as defined in armsrc/apps.h TRACE_SIZE +#define TRACE_BUFFER_SIZE 3000 #define SAMPLE_BUFFER_SIZE 64 - extern uint8_t* sample_buf; extern size_t sample_buf_len; #define arraylen(x) (sizeof(x)/sizeof((x)[0])) From 0c03a4f7191af64f1f894965bd17aa6ac96a1d98 Mon Sep 17 00:00:00 2001 From: Peter Fillmore Date: Sun, 16 Nov 2014 22:54:54 +1100 Subject: [PATCH 2/2] changed parity calculation from large table to a small function changed parity calculation to be on-the-fly during tag modulation changed calls to parity function to use smaller function --- armsrc/iclass.c | 12 ++++++++---- armsrc/iso14443a.c | 18 ++++++++++++++---- armsrc/iso14443a.h | 2 +- armsrc/util.c | 8 ++++++++ armsrc/util.h | 3 +++ 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/armsrc/iclass.c b/armsrc/iclass.c index 0ee1b355..861ed149 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -226,7 +226,8 @@ static RAMFUNC int OutOfNDecoding(int bit) // Calculate the parity bit for the client... Uart.parityBits <<= 1; - Uart.parityBits ^= OddByteParity[(Uart.shiftReg & 0xff)]; + //Uart.parityBits ^= OddByteParity[(Uart.shiftReg & 0xff)]; + Uart.parityBits ^= oddparity(Uart.shiftReg & 0xff); Uart.bitCnt = 0; Uart.shiftReg = 0; @@ -249,7 +250,8 @@ static RAMFUNC int OutOfNDecoding(int bit) // Calculate the parity bit for the client... Uart.parityBits <<= 1; - Uart.parityBits ^= OddByteParity[(Uart.dropPosition & 0xff)]; + //Uart.parityBits ^= OddByteParity[(Uart.dropPosition & 0xff)]; + Uart.parityBits ^= oddparity((Uart.dropPosition & 0xff)); Uart.bitCnt = 0; Uart.shiftReg = 0; @@ -486,7 +488,8 @@ static RAMFUNC int ManchesterDecoding(int v) Demod.output[Demod.len] = 0x0f; Demod.len++; Demod.parityBits <<= 1; - Demod.parityBits ^= OddByteParity[0x0f]; + //Demod.parityBits ^= OddByteParity[0x0f]; + Demod.parityBits ^= oddparity(0x0f); Demod.state = DEMOD_UNSYNCD; // error = 0x0f; return TRUE; @@ -611,7 +614,8 @@ static RAMFUNC int ManchesterDecoding(int v) // FOR ISO15639 PARITY NOT SEND OTA, JUST CALCULATE IT FOR THE CLIENT Demod.parityBits <<= 1; - Demod.parityBits ^= OddByteParity[(Demod.shiftReg & 0xff)]; + //Demod.parityBits ^= OddByteParity[(Demod.shiftReg & 0xff)]; + Demod.parityBits ^= oddparity(Demod.shiftReg & 0xff); Demod.bitCount = 0; Demod.shiftReg = 0; diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index 01cf2486..61273108 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -125,6 +125,8 @@ uint32_t LastProxToAirDuration; #define SEC_Y 0x00 #define SEC_Z 0xc0 +//replaced large parity table with small parity generation function - saves flash code +/* const uint8_t OddByteParity[256] = { 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, @@ -143,8 +145,7 @@ const uint8_t OddByteParity[256] = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1 }; - - +*/ void iso14a_set_trigger(bool enable) { trigger = enable; } @@ -166,10 +167,14 @@ void iso14a_set_timeout(uint32_t timeout) { // Generate the parity value for a byte sequence // //----------------------------------------------------------------------------- +/* byte_t oddparity (const byte_t bt) { return OddByteParity[bt]; } +*/ + + uint32_t GetParity(const uint8_t * pbtCmd, int iLen) { @@ -179,7 +184,8 @@ uint32_t GetParity(const uint8_t * pbtCmd, int iLen) // Generate the parity bits for (i = 0; i < iLen; i++) { // and save them to a 32Bit word - dwPar |= ((OddByteParity[pbtCmd[i]]) << i); + //dwPar |= ((OddByteParity[pbtCmd[i]]) << i); + dwPar |= (oddparity(pbtCmd[i]) << i); } return dwPar; } @@ -648,6 +654,7 @@ void RAMFUNC SnoopIso14443a(uint8_t param) { //----------------------------------------------------------------------------- // Prepare tag messages +//16/11/2014 - changed to calculate parity on the fly - Peter Fillmore //----------------------------------------------------------------------------- static void CodeIso14443aAsTagPar(const uint8_t *cmd, int len, uint32_t dwParity) { @@ -684,13 +691,16 @@ static void CodeIso14443aAsTagPar(const uint8_t *cmd, int len, uint32_t dwParity } // Get the parity bit - if ((dwParity >> i) & 0x01) { + // changed to generate parity on the fly + //if ((dwParity >> i) & 0x01) { + if (oddparity(cmd[i]) & 0x01) { ToSend[++ToSendMax] = SEC_D; LastProxToAirDuration = 8 * ToSendMax - 4; } else { ToSend[++ToSendMax] = SEC_E; LastProxToAirDuration = 8 * ToSendMax; } + } // Send stopbit diff --git a/armsrc/iso14443a.h b/armsrc/iso14443a.h index 6d18515f..ff00485a 100644 --- a/armsrc/iso14443a.h +++ b/armsrc/iso14443a.h @@ -75,7 +75,7 @@ typedef struct { -extern byte_t oddparity (const byte_t bt); +//extern uint8_t oddparity(uint8_t bt); extern uint32_t GetParity(const uint8_t *pbtCmd, int iLen); extern void AppendCrc14443a(uint8_t *data, int len); diff --git a/armsrc/util.c b/armsrc/util.c index 5b68f513..cee42a29 100644 --- a/armsrc/util.c +++ b/armsrc/util.c @@ -44,7 +44,15 @@ uint64_t bytes_to_num(uint8_t* src, size_t len) } return num; } +//added here for parity calulations +uint8_t oddparity(uint8_t bt) +{ + uint16_t v = bt; + v ^= v >> 4; + v &= 0xF; + return ((0x9669 >> v) & 1); +} void LEDsoff() { LED_A_OFF(); diff --git a/armsrc/util.h b/armsrc/util.h index e8b9cdff..fd787746 100644 --- a/armsrc/util.h +++ b/armsrc/util.h @@ -32,6 +32,9 @@ uint32_t SwapBits(uint32_t value, int nrbits); void num_to_bytes(uint64_t n, size_t len, uint8_t* dest); uint64_t bytes_to_num(uint8_t* src, size_t len); +//added parity generation function here +uint8_t oddparity(uint8_t bt); + void SpinDelay(int ms); void SpinDelayUs(int us); void LED(int led, int ms);