This commit is contained in:
Peter Fillmore 2014-12-19 01:39:11 +00:00
commit 6f934faf2c
10 changed files with 53 additions and 23 deletions

View file

@ -226,7 +226,8 @@ static RAMFUNC int OutOfNDecoding(int bit)
// Calculate the parity bit for the client... // Calculate the parity bit for the client...
Uart.parityBits <<= 1; 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.bitCnt = 0;
Uart.shiftReg = 0; Uart.shiftReg = 0;
@ -249,7 +250,8 @@ static RAMFUNC int OutOfNDecoding(int bit)
// Calculate the parity bit for the client... // Calculate the parity bit for the client...
Uart.parityBits <<= 1; 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.bitCnt = 0;
Uart.shiftReg = 0; Uart.shiftReg = 0;
@ -486,7 +488,8 @@ static RAMFUNC int ManchesterDecoding(int v)
Demod.output[Demod.len] = 0x0f; Demod.output[Demod.len] = 0x0f;
Demod.len++; Demod.len++;
Demod.parityBits <<= 1; Demod.parityBits <<= 1;
Demod.parityBits ^= OddByteParity[0x0f]; //Demod.parityBits ^= OddByteParity[0x0f];
Demod.parityBits ^= oddparity(0x0f);
Demod.state = DEMOD_UNSYNCD; Demod.state = DEMOD_UNSYNCD;
// error = 0x0f; // error = 0x0f;
return TRUE; return TRUE;
@ -611,7 +614,8 @@ static RAMFUNC int ManchesterDecoding(int v)
// FOR ISO15639 PARITY NOT SEND OTA, JUST CALCULATE IT FOR THE CLIENT // FOR ISO15639 PARITY NOT SEND OTA, JUST CALCULATE IT FOR THE CLIENT
Demod.parityBits <<= 1; 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.bitCount = 0;
Demod.shiftReg = 0; Demod.shiftReg = 0;

View file

@ -125,6 +125,8 @@ uint32_t LastProxToAirDuration;
#define SEC_Y 0x00 #define SEC_Y 0x00
#define SEC_Z 0xc0 #define SEC_Z 0xc0
//replaced large parity table with small parity generation function - saves flash code
/*
const uint8_t OddByteParity[256] = { const uint8_t OddByteParity[256] = {
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 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, 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, 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 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1
}; };
*/
void iso14a_set_trigger(bool enable) { void iso14a_set_trigger(bool enable) {
trigger = enable; trigger = enable;
} }
@ -166,10 +167,14 @@ void iso14a_set_timeout(uint32_t timeout) {
// Generate the parity value for a byte sequence // Generate the parity value for a byte sequence
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/*
byte_t oddparity (const byte_t bt) byte_t oddparity (const byte_t bt)
{ {
return OddByteParity[bt]; return OddByteParity[bt];
} }
*/
uint32_t GetParity(const uint8_t * pbtCmd, int iLen) 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 // Generate the parity bits
for (i = 0; i < iLen; i++) { for (i = 0; i < iLen; i++) {
// and save them to a 32Bit word // and save them to a 32Bit word
dwPar |= ((OddByteParity[pbtCmd[i]]) << i); //dwPar |= ((OddByteParity[pbtCmd[i]]) << i);
dwPar |= (oddparity(pbtCmd[i]) << i);
} }
return dwPar; return dwPar;
} }
@ -648,6 +654,7 @@ void RAMFUNC SnoopIso14443a(uint8_t param) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Prepare tag messages // 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) 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 // 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; ToSend[++ToSendMax] = SEC_D;
LastProxToAirDuration = 8 * ToSendMax - 4; LastProxToAirDuration = 8 * ToSendMax - 4;
} else { } else {
ToSend[++ToSendMax] = SEC_E; ToSend[++ToSendMax] = SEC_E;
LastProxToAirDuration = 8 * ToSendMax; LastProxToAirDuration = 8 * ToSendMax;
} }
} }
// Send stopbit // Send stopbit

View file

@ -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 uint32_t GetParity(const uint8_t *pbtCmd, int iLen);
extern void AppendCrc14443a(uint8_t *data, int len); extern void AppendCrc14443a(uint8_t *data, int len);

View file

@ -44,7 +44,15 @@ uint64_t bytes_to_num(uint8_t* src, size_t len)
} }
return num; 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() void LEDsoff()
{ {
LED_A_OFF(); LED_A_OFF();

View file

@ -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); void num_to_bytes(uint64_t n, size_t len, uint8_t* dest);
uint64_t bytes_to_num(uint8_t* src, size_t len); 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 SpinDelay(int ms);
void SpinDelayUs(int us); void SpinDelayUs(int us);
void LED(int led, int ms); void LED(int led, int ms);

View file

@ -31,7 +31,6 @@ int CmdHF14AList(const char *Cmd)
{ {
bool ShowWaitCycles = false; bool ShowWaitCycles = false;
char param = param_getchar(Cmd, 0); char param = param_getchar(Cmd, 0);
if (param == 'h' || (param != 0 && param != 'f')) { if (param == 'h' || (param != 0 && param != 'f')) {
PrintAndLog("List data in trace buffer."); PrintAndLog("List data in trace buffer.");
PrintAndLog("Usage: hf 14a list [f]"); PrintAndLog("Usage: hf 14a list [f]");
@ -44,7 +43,8 @@ int CmdHF14AList(const char *Cmd)
ShowWaitCycles = true; 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); GetFromBigBuf(got,sizeof(got),0);
WaitForResponse(CMD_ACK,NULL); WaitForResponse(CMD_ACK,NULL);
@ -62,7 +62,7 @@ int CmdHF14AList(const char *Cmd)
uint32_t EndOfTransmissionTimestamp = 0; uint32_t EndOfTransmissionTimestamp = 0;
for (;;) { for (;;) {
if(i >= 1900) { if(i >= TRACE_BUFFER_SIZE) {
break; break;
} }
@ -86,7 +86,7 @@ int CmdHF14AList(const char *Cmd)
if (len > 100) { if (len > 100) {
break; break;
} }
if (i + len >= 1900) { if (i + len >= TRACE_BUFFER_SIZE) {
break; break;
} }

View file

@ -145,7 +145,7 @@ demodError:
int CmdHF14BList(const char *Cmd) int CmdHF14BList(const char *Cmd)
{ {
uint8_t got[960]; uint8_t got[TRACE_BUFFER_SIZE];
GetFromBigBuf(got,sizeof(got),0); GetFromBigBuf(got,sizeof(got),0);
WaitForResponse(CMD_ACK,NULL); WaitForResponse(CMD_ACK,NULL);
@ -157,7 +157,8 @@ int CmdHF14BList(const char *Cmd)
int prev = -1; int prev = -1;
for(;;) { for(;;) {
if(i >= 900) { //if(i >= 900) {
if(i >= TRACE_BUFFER_SIZE) {
break; break;
} }
@ -176,7 +177,8 @@ int CmdHF14BList(const char *Cmd)
if(len > 100) { if(len > 100) {
break; break;
} }
if(i + len >= 900) { //if(i + len >= 900) {
if(i + len >= TRACE_BUFFER_SIZE) {
break; break;
} }

View file

@ -56,7 +56,8 @@ int CmdHFiClassList(const char *Cmd)
return 0; return 0;
} }
uint8_t got[1920]; //uint8_t got[1920];
uint8_t got[TRACE_BUFFER_SIZE];
GetFromBigBuf(got,sizeof(got),0); GetFromBigBuf(got,sizeof(got),0);
WaitForResponse(CMD_ACK,NULL); WaitForResponse(CMD_ACK,NULL);
@ -78,7 +79,7 @@ int CmdHFiClassList(const char *Cmd)
uint32_t EndOfTransmissionTimestamp = 0; uint32_t EndOfTransmissionTimestamp = 0;
for( i=0; i < 1900;) for( i=0; i < TRACE_BUFFER_SIZE;)
{ {
//First 32 bits contain //First 32 bits contain
// isResponse (1 bit) // isResponse (1 bit)

View file

@ -30,7 +30,7 @@ size_t nbytes(size_t nbits) {
int CmdLFHitagList(const char *Cmd) int CmdLFHitagList(const char *Cmd)
{ {
uint8_t got[3000]; uint8_t got[TRACE_BUFFER_SIZE];
GetFromBigBuf(got,sizeof(got),0); GetFromBigBuf(got,sizeof(got),0);
WaitForResponse(CMD_ACK,NULL); WaitForResponse(CMD_ACK,NULL);
@ -42,7 +42,8 @@ int CmdLFHitagList(const char *Cmd)
int prev = -1; int prev = -1;
for (;;) { for (;;) {
if(i >= 1900) { //if(i >= 1900) {
if(i >= TRACE_BUFFER_SIZE) {
break; break;
} }
@ -69,7 +70,8 @@ int CmdLFHitagList(const char *Cmd)
if (len > 100) { if (len > 100) {
break; break;
} }
if (i + len >= 1900) { //if (i + len >= 1900) {
if (i + len >= TRACE_BUFFER_SIZE) {
break; break;
} }

View file

@ -12,9 +12,9 @@
#define DATA_H__ #define DATA_H__
#include <stdint.h> #include <stdint.h>
//trace buffer size as defined in armsrc/apps.h TRACE_SIZE
#define TRACE_BUFFER_SIZE 3000
#define SAMPLE_BUFFER_SIZE 64 #define SAMPLE_BUFFER_SIZE 64
extern uint8_t* sample_buf; extern uint8_t* sample_buf;
extern size_t sample_buf_len; extern size_t sample_buf_len;
#define arraylen(x) (sizeof(x)/sizeof((x)[0])) #define arraylen(x) (sizeof(x)/sizeof((x)[0]))