FIX: thanks @tony, for pointing out a "end" statement inside tnp3sim.lua

ADD: @marshmello42 fixs for t55x7
This commit is contained in:
iceman1001 2015-10-16 23:16:46 +02:00
commit a739812e89
9 changed files with 97 additions and 106 deletions

View file

@ -50,8 +50,14 @@ uint8_t *BigBuf_get_EM_addr(void)
// clear ALL of BigBuf // clear ALL of BigBuf
void BigBuf_Clear(void) void BigBuf_Clear(void)
{
BigBuf_Clear_ext(true);
}
// clear ALL of BigBuf
void BigBuf_Clear_ext(bool verbose)
{ {
memset(BigBuf,0,BIGBUF_SIZE); memset(BigBuf,0,BIGBUF_SIZE);
if (verbose)
Dbprintf("Buffer cleared (%i bytes)",BIGBUF_SIZE); Dbprintf("Buffer cleared (%i bytes)",BIGBUF_SIZE);
} }

View file

@ -25,6 +25,7 @@ extern uint8_t *BigBuf_get_addr(void);
extern uint8_t *BigBuf_get_EM_addr(void); extern uint8_t *BigBuf_get_EM_addr(void);
extern uint16_t BigBuf_max_traceLen(void); extern uint16_t BigBuf_max_traceLen(void);
extern void BigBuf_Clear(void); extern void BigBuf_Clear(void);
extern void BigBuf_Clear_ext(bool verbose);
extern uint8_t *BigBuf_malloc(uint16_t); extern uint8_t *BigBuf_malloc(uint16_t);
extern void BigBuf_free(void); extern void BigBuf_free(void);
extern void BigBuf_free_keep_EM(void); extern void BigBuf_free_keep_EM(void);

View file

@ -242,11 +242,13 @@ void AcquireTiType(void)
int i, j, n; int i, j, n;
// tag transmission is <20ms, sampling at 2M gives us 40K samples max // tag transmission is <20ms, sampling at 2M gives us 40K samples max
// each sample is 1 bit stuffed into a uint32_t so we need 1250 uint32_t // each sample is 1 bit stuffed into a uint32_t so we need 1250 uint32_t
#define TIBUFLEN 1250 #define TIBUFLEN 1250
// clear buffer // clear buffer
uint32_t *BigBuf = (uint32_t *)BigBuf_get_addr(); uint32_t *buf = (uint32_t *)BigBuf_get_addr();
memset(BigBuf,0,BigBuf_max_traceLen()/sizeof(uint32_t));
//clear buffer now so it does not interfere with timing later
BigBuf_Clear_ext(false);
// Set up the synchronous serial port // Set up the synchronous serial port
AT91C_BASE_PIOA->PIO_PDR = GPIO_SSC_DIN; AT91C_BASE_PIOA->PIO_PDR = GPIO_SSC_DIN;
@ -284,7 +286,7 @@ void AcquireTiType(void)
i = 0; i = 0;
for(;;) { for(;;) {
if(AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) { if(AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
BigBuf[i] = AT91C_BASE_SSC->SSC_RHR; // store 32 bit values in buffer buf[i] = AT91C_BASE_SSC->SSC_RHR; // store 32 bit values in buffer
i++; if(i >= TIBUFLEN) break; i++; if(i >= TIBUFLEN) break;
} }
WDT_HIT(); WDT_HIT();
@ -295,11 +297,12 @@ void AcquireTiType(void)
AT91C_BASE_PIOA->PIO_ASR = GPIO_SSC_DIN | GPIO_SSC_DOUT; AT91C_BASE_PIOA->PIO_ASR = GPIO_SSC_DIN | GPIO_SSC_DOUT;
char *dest = (char *)BigBuf_get_addr(); char *dest = (char *)BigBuf_get_addr();
n = TIBUFLEN*32; n = TIBUFLEN * 32;
// unpack buffer // unpack buffer
for (i=TIBUFLEN-1; i>=0; i--) { for (i = TIBUFLEN-1; i >= 0; i--) {
for (j=0; j<32; j++) { for (j = 0; j < 32; j++) {
if(BigBuf[i] & (1 << j)) { if(buf[i] & (1 << j)) {
dest[--n] = 1; dest[--n] = 1;
} else { } else {
dest[--n] = -1; dest[--n] = -1;
@ -324,8 +327,7 @@ void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc)
crc = update_crc16(crc, (idhi>>16)&0xff); crc = update_crc16(crc, (idhi>>16)&0xff);
crc = update_crc16(crc, (idhi>>24)&0xff); crc = update_crc16(crc, (idhi>>24)&0xff);
} }
Dbprintf("Writing to tag: %x%08x, crc=%x", Dbprintf("Writing to tag: %x%08x, crc=%x", (unsigned int) idhi, (unsigned int) idlo, crc);
(unsigned int) idhi, (unsigned int) idlo, crc);
// TI tags charge at 134.2Khz // TI tags charge at 134.2Khz
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz
@ -389,12 +391,11 @@ void SimulateTagLowFrequency(int period, int gap, int ledcontrol)
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT); FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT);
AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT | GPIO_SSC_CLK; AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT | GPIO_SSC_CLK;
AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT; AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
AT91C_BASE_PIOA->PIO_ODR = GPIO_SSC_CLK; AT91C_BASE_PIOA->PIO_ODR = GPIO_SSC_CLK;
#define SHORT_COIL() LOW(GPIO_SSC_DOUT) #define SHORT_COIL() LOW(GPIO_SSC_DOUT)
#define OPEN_COIL() HIGH(GPIO_SSC_DOUT) #define OPEN_COIL() HIGH(GPIO_SSC_DOUT)
i = 0; i = 0;
for(;;) { for(;;) {
@ -406,16 +407,15 @@ void SimulateTagLowFrequency(int period, int gap, int ledcontrol)
} }
WDT_HIT(); WDT_HIT();
} }
if (ledcontrol) if (ledcontrol) LED_D_ON();
LED_D_ON();
if(tab[i]) if(tab[i])
OPEN_COIL(); OPEN_COIL();
else else
SHORT_COIL(); SHORT_COIL();
if (ledcontrol) if (ledcontrol) LED_D_OFF();
LED_D_OFF();
//wait until SSC_CLK goes LOW //wait until SSC_CLK goes LOW
while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK) { while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK) {
if(BUTTON_PRESS()) { if(BUTTON_PRESS()) {
@ -569,12 +569,9 @@ void CmdHIDsimTAG(int hi, int lo, int ledcontrol)
} }
} }
if (ledcontrol) if (ledcontrol) LED_A_ON();
LED_A_ON();
SimulateTagLowFrequency(n, 0, ledcontrol); SimulateTagLowFrequency(n, 0, ledcontrol);
if (ledcontrol) LED_A_OFF();
if (ledcontrol)
LED_A_OFF();
} }
// prepare a waveform pattern in the buffer based on the ID given then // prepare a waveform pattern in the buffer based on the ID given then
@ -677,21 +674,10 @@ void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
if (separator==1) Dbprintf("sorry but separator option not yet available"); if (separator==1) Dbprintf("sorry but separator option not yet available");
Dbprintf("Simulating with clk: %d, invert: %d, encoding: %d, separator: %d, n: %d",clk, invert, encoding, separator, n); Dbprintf("Simulating with clk: %d, invert: %d, encoding: %d, separator: %d, n: %d",clk, invert, encoding, separator, n);
//DEBUG
//Dbprintf("First 32:");
//uint8_t *dest = BigBuf_get_addr();
//i=0;
//Dbprintf("%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d", dest[i],dest[i+1],dest[i+2],dest[i+3],dest[i+4],dest[i+5],dest[i+6],dest[i+7],dest[i+8],dest[i+9],dest[i+10],dest[i+11],dest[i+12],dest[i+13],dest[i+14],dest[i+15]);
//i+=16;
//Dbprintf("%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d", dest[i],dest[i+1],dest[i+2],dest[i+3],dest[i+4],dest[i+5],dest[i+6],dest[i+7],dest[i+8],dest[i+9],dest[i+10],dest[i+11],dest[i+12],dest[i+13],dest[i+14],dest[i+15]);
if (ledcontrol)
LED_A_ON();
if (ledcontrol) LED_A_ON();
SimulateTagLowFrequency(n, 0, ledcontrol); SimulateTagLowFrequency(n, 0, ledcontrol);
if (ledcontrol) LED_A_OFF();
if (ledcontrol)
LED_A_OFF();
} }
//carrier can be 2,4 or 8 //carrier can be 2,4 or 8
@ -720,7 +706,7 @@ static void pskSimBit(uint8_t waveLen, int *n, uint8_t clk, uint8_t *curPhase, b
// args clock, carrier, invert, // args clock, carrier, invert,
void CmdPSKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream) void CmdPSKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
{ {
int ledcontrol=1; int ledcontrol = 1;
int n=0, i=0; int n=0, i=0;
uint8_t clk = arg1 >> 8; uint8_t clk = arg1 >> 8;
uint8_t carrier = arg1 & 0xFF; uint8_t carrier = arg1 & 0xFF;
@ -734,26 +720,16 @@ void CmdPSKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
} }
} }
Dbprintf("Simulating with Carrier: %d, clk: %d, invert: %d, n: %d",carrier, clk, invert, n); Dbprintf("Simulating with Carrier: %d, clk: %d, invert: %d, n: %d",carrier, clk, invert, n);
//Dbprintf("DEBUG: First 32:");
//uint8_t *dest = BigBuf_get_addr();
//i=0;
//Dbprintf("%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d", dest[i],dest[i+1],dest[i+2],dest[i+3],dest[i+4],dest[i+5],dest[i+6],dest[i+7],dest[i+8],dest[i+9],dest[i+10],dest[i+11],dest[i+12],dest[i+13],dest[i+14],dest[i+15]);
//i+=16;
//Dbprintf("%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d", dest[i],dest[i+1],dest[i+2],dest[i+3],dest[i+4],dest[i+5],dest[i+6],dest[i+7],dest[i+8],dest[i+9],dest[i+10],dest[i+11],dest[i+12],dest[i+13],dest[i+14],dest[i+15]);
if (ledcontrol) if (ledcontrol) LED_A_ON();
LED_A_ON();
SimulateTagLowFrequency(n, 0, ledcontrol); SimulateTagLowFrequency(n, 0, ledcontrol);
if (ledcontrol) LED_A_OFF();
if (ledcontrol)
LED_A_OFF();
} }
// loop to get raw HID waveform then FSK demodulate the TAG ID from it // loop to get raw HID waveform then FSK demodulate the TAG ID from it
void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol) void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
{ {
uint8_t *dest = BigBuf_get_addr(); uint8_t *dest = BigBuf_get_addr();
//const size_t sizeOfBigBuff = BigBuf_max_traceLen();
size_t size = 0; size_t size = 0;
uint32_t hi2=0, hi=0, lo=0; uint32_t hi2=0, hi=0, lo=0;
int idx=0; int idx=0;
@ -767,7 +743,6 @@ void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
DoAcquisition_default(-1,true); DoAcquisition_default(-1,true);
// FSK demodulator // FSK demodulator
//size = sizeOfBigBuff; //variable size will change after demod so re initialize it before use
size = 50*128*2; //big enough to catch 2 sequences of largest format size = 50*128*2; //big enough to catch 2 sequences of largest format
idx = HIDdemodFSK(dest, &size, &hi2, &hi, &lo); idx = HIDdemodFSK(dest, &size, &hi2, &hi, &lo);
@ -775,12 +750,16 @@ void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
// go over previously decoded manchester data and decode into usable tag ID // go over previously decoded manchester data and decode into usable tag ID
if (hi2 != 0){ //extra large HID tags 88/192 bits if (hi2 != 0){ //extra large HID tags 88/192 bits
Dbprintf("TAG ID: %x%08x%08x (%d)", Dbprintf("TAG ID: %x%08x%08x (%d)",
(unsigned int) hi2, (unsigned int) hi, (unsigned int) lo, (unsigned int) (lo>>1) & 0xFFFF); (unsigned int) hi2,
(unsigned int) hi,
(unsigned int) lo,
(unsigned int) (lo>>1) & 0xFFFF
);
}else { //standard HID tags 44/96 bits }else { //standard HID tags 44/96 bits
//Dbprintf("TAG ID: %x%08x (%d)",(unsigned int) hi, (unsigned int) lo, (unsigned int) (lo>>1) & 0xFFFF); //old print cmd
uint8_t bitlen = 0; uint8_t bitlen = 0;
uint32_t fc = 0; uint32_t fc = 0;
uint32_t cardnum = 0; uint32_t cardnum = 0;
if (((hi>>5)&1) == 1){//if bit 38 is set then < 37 bit format is used if (((hi>>5)&1) == 1){//if bit 38 is set then < 37 bit format is used
uint32_t lo2=0; uint32_t lo2=0;
lo2=(((hi & 31) << 12) | (lo>>20)); //get bits 21-37 to check for format len bit lo2=(((hi & 31) << 12) | (lo>>20)); //get bits 21-37 to check for format len bit
@ -818,11 +797,13 @@ void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
fc = ((hi&0xF)<<12)|(lo>>20); fc = ((hi&0xF)<<12)|(lo>>20);
} }
} }
//Dbprintf("TAG ID: %x%08x (%d)",
// (unsigned int) hi, (unsigned int) lo, (unsigned int) (lo>>1) & 0xFFFF);
Dbprintf("TAG ID: %x%08x (%d) - Format Len: %dbit - FC: %d - Card: %d", Dbprintf("TAG ID: %x%08x (%d) - Format Len: %dbit - FC: %d - Card: %d",
(unsigned int) hi, (unsigned int) lo, (unsigned int) (lo>>1) & 0xFFFF, (unsigned int) hi,
(unsigned int) bitlen, (unsigned int) fc, (unsigned int) cardnum); (unsigned int) lo,
(unsigned int) (lo>>1) & 0xFFFF,
(unsigned int) bitlen,
(unsigned int) fc,
(unsigned int) cardnum);
} }
if (findone){ if (findone){
if (ledcontrol) LED_A_OFF(); if (ledcontrol) LED_A_OFF();
@ -843,7 +824,6 @@ void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
void CmdAWIDdemodFSK(int findone, int *high, int *low, int ledcontrol) void CmdAWIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
{ {
uint8_t *dest = BigBuf_get_addr(); uint8_t *dest = BigBuf_get_addr();
//const size_t sizeOfBigBuff = BigBuf_max_traceLen();
size_t size; size_t size;
int idx=0; int idx=0;
// Configure to go in 125Khz listen mode // Configure to go in 125Khz listen mode
@ -856,7 +836,6 @@ void CmdAWIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
DoAcquisition_default(-1,true); DoAcquisition_default(-1,true);
// FSK demodulator // FSK demodulator
//size = sizeOfBigBuff; //variable size will change after demod so re initialize it before use
size = 50*128*2; //big enough to catch 2 sequences of largest format size = 50*128*2; //big enough to catch 2 sequences of largest format
idx = AWIDdemodFSK(dest, &size); idx = AWIDdemodFSK(dest, &size);
@ -1041,7 +1020,7 @@ void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol)
code = bytebits_to_byte(dest+idx,32); code = bytebits_to_byte(dest+idx,32);
code2 = bytebits_to_byte(dest+idx+32,32); code2 = bytebits_to_byte(dest+idx+32,32);
version = bytebits_to_byte(dest+idx+27,8); //14,4 version = bytebits_to_byte(dest+idx+27,8); //14,4
facilitycode = bytebits_to_byte(dest+idx+18,8); facilitycode = bytebits_to_byte(dest+idx+18,8);
number = (bytebits_to_byte(dest+idx+36,8)<<8)|(bytebits_to_byte(dest+idx+45,8)); //36,9 number = (bytebits_to_byte(dest+idx+36,8)<<8)|(bytebits_to_byte(dest+idx+45,8)); //36,9
crc = bytebits_to_byte(dest+idx+54,8); crc = bytebits_to_byte(dest+idx+54,8);
@ -1056,7 +1035,6 @@ void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol)
// if we're only looking for one tag // if we're only looking for one tag
if (findone){ if (findone){
if (ledcontrol) LED_A_OFF(); if (ledcontrol) LED_A_OFF();
//LED_A_OFF();
*high=code; *high=code;
*low=code2; *low=code2;
return; return;
@ -1139,6 +1117,7 @@ void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol)
#define WRITE_GAP 20*8 // was 160 // SPEC: 1*8 to 20*8 - typ 10*8 (or 10fc) #define WRITE_GAP 20*8 // was 160 // SPEC: 1*8 to 20*8 - typ 10*8 (or 10fc)
#define WRITE_0 16*8 // was 144 // SPEC: 16*8 to 32*8 - typ 24*8 (or 24fc) #define WRITE_0 16*8 // was 144 // SPEC: 16*8 to 32*8 - typ 24*8 (or 24fc)
#define WRITE_1 50*8 // was 400 // SPEC: 48*8 to 64*8 - typ 56*8 (or 56fc) 432 for T55x7; 448 for E5550 #define WRITE_1 50*8 // was 400 // SPEC: 48*8 to 64*8 - typ 56*8 (or 56fc) 432 for T55x7; 448 for E5550
#define READ_GAP 52*8
// VALUES TAKEN FROM EM4x function: SendForward // VALUES TAKEN FROM EM4x function: SendForward
// START_GAP = 440; (55*8) cycles at 125Khz (8us = 1cycle) // START_GAP = 440; (55*8) cycles at 125Khz (8us = 1cycle)
@ -1154,6 +1133,12 @@ void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol)
// T0 = TIMER_CLOCK1 / 125000 = 192 // T0 = TIMER_CLOCK1 / 125000 = 192
// 1 Cycle = 8 microseconds(us) == 1 field clock // 1 Cycle = 8 microseconds(us) == 1 field clock
void TurnReadLFOn(int delay) {
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
// Give it a bit of time for the resonant antenna to settle.
SpinDelayUs(delay); //155*8 //50*8
}
// Write one bit to card // Write one bit to card
void T55xxWriteBit(int bit) { void T55xxWriteBit(int bit) {
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD); FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
@ -1183,18 +1168,18 @@ void T55xxWriteBlock(uint32_t Data, uint32_t Block, uint32_t Pwd, uint8_t PwdMod
T55xxWriteBit(0); //Page 0 T55xxWriteBit(0); //Page 0
if (PwdMode == 1){ if (PwdMode == 1){
// Send pwd // Send Pwd
for (i = 0x80000000; i != 0; i >>= 1) for (i = 0x80000000; i != 0; i >>= 1)
T55xxWriteBit(Pwd & i); T55xxWriteBit(Pwd & i);
} }
// Send lock bit // Send Lock bit
T55xxWriteBit(0); T55xxWriteBit(0);
// Send data // Send Data
for (i = 0x80000000; i != 0; i >>= 1) for (i = 0x80000000; i != 0; i >>= 1)
T55xxWriteBit(Data & i); T55xxWriteBit(Data & i);
// Send block number // Send Block number
for (i = 0x04; i != 0; i >>= 1) for (i = 0x04; i != 0; i >>= 1)
T55xxWriteBit(Block & i); T55xxWriteBit(Block & i);
@ -1202,24 +1187,21 @@ void T55xxWriteBlock(uint32_t Data, uint32_t Block, uint32_t Pwd, uint8_t PwdMod
// so wait a little more) // so wait a little more)
TurnReadLFOn(20 * 1000); TurnReadLFOn(20 * 1000);
// field off // turn field off
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
cmd_send(CMD_ACK,0,0,0,0,0); cmd_send(CMD_ACK,0,0,0,0,0);
LED_A_OFF(); LED_A_OFF();
} }
void TurnReadLFOn(int delay) {
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
// Give it a bit of time for the resonant antenna to settle.
SpinDelayUs(delay);
}
// Read one card block in page 0 // Read one card block in page 0
void T55xxReadBlock(uint32_t Block, uint32_t Pwd, uint8_t PwdMode) { void T55xxReadBlock(uint32_t Block, uint32_t Pwd, uint8_t PwdMode) {
LED_A_ON(); LED_A_ON();
uint32_t i = 0; uint32_t i = 0;
//clear buffer now so it does not interfere with timing later
BigBuf_Clear_ext(false);
//make sure block is at max 7 //make sure block is at max 7
Block &= 0x7; Block &= 0x7;
@ -1227,6 +1209,7 @@ void T55xxReadBlock(uint32_t Block, uint32_t Pwd, uint8_t PwdMode) {
LFSetupFPGAForADC(95, true); LFSetupFPGAForADC(95, true);
// Trigger T55x7 in mode. // Trigger T55x7 in mode.
// Trigger T55x7 Direct Access Mode
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
SpinDelayUs(START_GAP); SpinDelayUs(START_GAP);
@ -1235,24 +1218,24 @@ void T55xxReadBlock(uint32_t Block, uint32_t Pwd, uint8_t PwdMode) {
T55xxWriteBit(0); //Page 0 T55xxWriteBit(0); //Page 0
if (PwdMode == 1){ if (PwdMode == 1){
// Send pwd // Send Pwd
for (i = 0x80000000; i != 0; i >>= 1) for (i = 0x80000000; i != 0; i >>= 1)
T55xxWriteBit(Pwd & i); T55xxWriteBit(Pwd & i);
} }
// Send a zero bit seperation // Send a zero bit separation
T55xxWriteBit(0); T55xxWriteBit(0);
// Send block number // Send Block number
for (i = 0x04; i != 0; i >>= 1) for (i = 0x04; i != 0; i >>= 1)
T55xxWriteBit(Block & i); T55xxWriteBit(Block & i);
// Turn field on to read the response // Turn field on to read the response
TurnReadLFOn(START_GAP); TurnReadLFOn(READ_GAP);
// Acquisition // Acquisition
doT55x7Acquisition(); doT55x7Acquisition();
// field off // turn field off
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
cmd_send(CMD_ACK,0,0,0,0,0); cmd_send(CMD_ACK,0,0,0,0,0);
LED_A_OFF(); LED_A_OFF();
@ -1262,10 +1245,13 @@ void T55xxReadBlock(uint32_t Block, uint32_t Pwd, uint8_t PwdMode) {
void T55xxReadTrace(void){ void T55xxReadTrace(void){
LED_A_ON(); LED_A_ON();
//clear buffer now so it does not interfere with timing later
BigBuf_Clear_ext(false);
// Set up FPGA, 125kHz // Set up FPGA, 125kHz
LFSetupFPGAForADC(95, true); LFSetupFPGAForADC(95, true);
// Trigger T55x7 in mode. // Trigger T55x7 Direct Access Mode
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
SpinDelayUs(START_GAP); SpinDelayUs(START_GAP);
@ -1274,12 +1260,12 @@ void T55xxReadTrace(void){
T55xxWriteBit(1); //Page 1 T55xxWriteBit(1); //Page 1
// Turn field on to read the response // Turn field on to read the response
TurnReadLFOn(START_GAP); TurnReadLFOn(READ_GAP);
// Acquisition // Acquisition
doT55x7Acquisition(); doT55x7Acquisition();
// field off // turn field off
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
cmd_send(CMD_ACK,0,0,0,0,0); cmd_send(CMD_ACK,0,0,0,0,0);
LED_A_OFF(); LED_A_OFF();
@ -1501,8 +1487,11 @@ void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo)
// Clock rate is stored in bits 8-15 of the card value // Clock rate is stored in bits 8-15 of the card value
clock = (card & 0xFF00) >> 8; clock = (card & 0xFF00) >> 8;
Dbprintf("Clock rate: %d", clock); Dbprintf("Clock rate: %d", clock);
switch (clock) switch (clock) {
{ case 50:
clock = T55x7_BITRATE_RF_50;
case 40:
clock = T55x7_BITRATE_RF_40;
case 32: case 32:
clock = T55x7_BITRATE_RF_32; clock = T55x7_BITRATE_RF_32;
break; break;
@ -1721,14 +1710,13 @@ void EM4xLogin(uint32_t Password) {
void EM4xReadWord(uint8_t Address, uint32_t Pwd, uint8_t PwdMode) { void EM4xReadWord(uint8_t Address, uint32_t Pwd, uint8_t PwdMode) {
uint8_t fwd_bit_count;
uint8_t *dest = BigBuf_get_addr(); uint8_t *dest = BigBuf_get_addr();
uint16_t bufferlength = BigBuf_max_traceLen(); uint16_t bufsize = BigBuf_max_traceLen();
uint32_t i = 0; uint32_t i = 0;
// Clear destination buffer before sending the command 0x80 = average. //clear buffer now so it does not interfere with timing later
memset(dest, 0x80, bufferlength); BigBuf_Clear_ext(false);
uint8_t fwd_bit_count;
//If password mode do login //If password mode do login
if (PwdMode == 1) EM4xLogin(Pwd); if (PwdMode == 1) EM4xLogin(Pwd);
@ -1753,7 +1741,7 @@ void EM4xReadWord(uint8_t Address, uint32_t Pwd, uint8_t PwdMode) {
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) { if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
dest[i] = (uint8_t)AT91C_BASE_SSC->SSC_RHR; dest[i] = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
++i; ++i;
if (i >= bufferlength) break; if (i >= bufsize) break;
} }
} }
@ -1786,11 +1774,10 @@ void CopyViKingtoT55x7(uint32_t block1, uint32_t block2) {
LED_D_ON(); LED_D_ON();
T55xxWriteBlock(block1,1,0,0); T55xxWriteBlock(block1,1,0,0);
T55xxWriteBlock(block2,2,0,0); T55xxWriteBlock(block2,2,0,0);
T55xxWriteBlock(T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_32 | 2 << T5555_MAXBLOCK_SHIFT,0,0,1); T55xxWriteBlock(T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_32 | 2 << T55x7_MAXBLOCK_SHIFT,0,0,0);
// T55xxWriteBlock(T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_32 | 2 << T5555_MAXBLOCK_SHIFT,0,0,1);
// ICEMAN NOTES: // ICEMAN NOTES:
// Shouldn't this one be: T55x7_MAXBLOCK_SHIFT and 0 in password mode // Shouldn't this one be: T55x7_MAXBLOCK_SHIFT and 0 in password mode
// like this:
// T55xxWriteBlock(T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_32 | 2 << T55x7_MAXBLOCK_SHIFT,0,0,0);
LED_D_OFF(); LED_D_OFF();
} }

View file

@ -266,7 +266,7 @@ void doT55x7Acquisition(void){
if ( bufsize > T55xx_SAMPLES_SIZE ) if ( bufsize > T55xx_SAMPLES_SIZE )
bufsize = T55xx_SAMPLES_SIZE; bufsize = T55xx_SAMPLES_SIZE;
memset(dest, 0, bufsize); //memset(dest, 0, bufsize);
uint16_t i = 0; uint16_t i = 0;
bool startFound = false; bool startFound = false;

View file

@ -47,7 +47,6 @@ uint32_t DoAcquisition_config( bool silent);
**/ **/
void LFSetupFPGAForADC(int divisor, bool lf_field); void LFSetupFPGAForADC(int divisor, bool lf_field);
/** /**
* Called from the USB-handler to set the sampling configuration * Called from the USB-handler to set the sampling configuration
* The sampling config is used for std reading and snooping. * The sampling config is used for std reading and snooping.

View file

@ -36,26 +36,25 @@ static int CmdHelp(const char *Cmd);
int usage_lf_cmdread() int usage_lf_cmdread()
{ {
PrintAndLog("Usage: lf cmdread <delay off> <zero> <one> <cmdbytes> [H] "); PrintAndLog("Usage: lf cmdread <delay off> <zero> <one> <cmdbytes> [H|L]");
PrintAndLog("Options: "); PrintAndLog("Options: ");
PrintAndLog(" h This help"); PrintAndLog(" h This help");
PrintAndLog(" L Low frequency (125 KHz)"); PrintAndLog(" <delay off> delay offset");
PrintAndLog(" H High frequency (134 KHz)"); PrintAndLog(" <zero> time period ZERO");
PrintAndLog(" H delay OFF"); PrintAndLog(" <one> time period ONE");
PrintAndLog(" H time period ZERO"); PrintAndLog(" [H|L] Frequency Low (125 KHz) / High (134 KHz)");
PrintAndLog(" H time period ONE");
PrintAndLog("Examples:"); PrintAndLog("Examples:");
PrintAndLog(" lf cmdread 80 100 200 11000"); PrintAndLog(" lf cmdread 80 100 200 11000");
PrintAndLog(" lf cmdread 80 100 100 11000 H"); PrintAndLog(" lf cmdread 80 100 100 11000 H");
return 0; return 0;
} }
/* send a command before reading */ /* send a LF command before reading */
int CmdLFCommandRead(const char *Cmd) int CmdLFCommandRead(const char *Cmd)
{ {
static char dummy[3] = {0x20,0x00,0x00}; static char dummy[3] = {0x20,0x00,0x00};
bool errors = FALSE; bool errors = FALSE;
uint8_t divisor = 0; //125khz uint8_t divisor = 95; //125khz
uint8_t cmdp =0; uint8_t cmdp =0;
while(param_getchar(Cmd, cmdp) != 0x00) while(param_getchar(Cmd, cmdp) != 0x00)
{ {

View file

@ -66,7 +66,7 @@ int usage_pcf7931_write(){
PrintAndLog("Options:"); PrintAndLog("Options:");
PrintAndLog(" h This help"); PrintAndLog(" h This help");
PrintAndLog(" blockaddress Block to save [0-7]"); PrintAndLog(" blockaddress Block to save [0-7]");
PrintAndLog(" byteaddress Index of byte inside block to write [0-16]"); PrintAndLog(" byteaddress Index of byte inside block to write [0-15]");
PrintAndLog(" data one byte of data (hex)"); PrintAndLog(" data one byte of data (hex)");
PrintAndLog("Examples:"); PrintAndLog("Examples:");
PrintAndLog(" lf pcf7931 write 2 1 FF"); PrintAndLog(" lf pcf7931 write 2 1 FF");
@ -136,7 +136,7 @@ int CmdLFPCF7931Write(const char *Cmd){
if ( param_getdec(Cmd, 0, &block) ) return usage_pcf7931_write(); if ( param_getdec(Cmd, 0, &block) ) return usage_pcf7931_write();
if ( param_getdec(Cmd, 1, &bytepos) ) return usage_pcf7931_write(); if ( param_getdec(Cmd, 1, &bytepos) ) return usage_pcf7931_write();
if ( (block > 7) || (bytepos > 16) ) return usage_pcf7931_write(); if ( (block > 7) || (bytepos > 15) ) return usage_pcf7931_write();
data = param_get8ex(Cmd, 2, 0, 16); data = param_get8ex(Cmd, 2, 0, 16);
@ -159,8 +159,8 @@ int CmdLFPCF7931Write(const char *Cmd){
static command_t CommandTable[] = static command_t CommandTable[] =
{ {
{"help", CmdHelp, 1, "This help"}, {"help", CmdHelp, 1, "This help"},
{"read", CmdLFPCF7931Read, 1, "Read content of a PCF7931 transponder"}, {"read", CmdLFPCF7931Read, 0, "Read content of a PCF7931 transponder"},
{"write", CmdLFPCF7931Write, 1, "Write data on a PCF7931 transponder."}, {"write", CmdLFPCF7931Write, 0, "Write data on a PCF7931 transponder."},
{"config", CmdLFPCF7931Config, 1, "Configure the password, the tags initialization delay and time offsets (optional)"}, {"config", CmdLFPCF7931Config, 1, "Configure the password, the tags initialization delay and time offsets (optional)"},
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };

View file

@ -262,8 +262,8 @@ int CmdT55xxReadBlock(const char *Cmd) {
uint8_t got[12000]; uint8_t got[12000];
GetFromBigBuf(got,sizeof(got),0); GetFromBigBuf(got,sizeof(got),0);
WaitForResponse(CMD_ACK,NULL); WaitForResponse(CMD_ACK,NULL);
setGraphBuf(got, 12000); setGraphBuf(got, sizeof(got));
DemodBufferLen=0; //DemodBufferLen=0;
if (!DecodeT55xxBlock()) return 3; if (!DecodeT55xxBlock()) return 3;
char blk[10]={0}; char blk[10]={0};
sprintf(blk,"%d", block); sprintf(blk,"%d", block);
@ -680,8 +680,8 @@ int CmdT55xxWriteBlock(const char *Cmd)
return 1; return 1;
} }
UsbCommand resp;
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}}; UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}};
UsbCommand resp;
c.d.asBytes[0] = 0x0; c.d.asBytes[0] = 0x0;
PrintAndLog("Writing to block: %d data : 0x%08X", block, data); PrintAndLog("Writing to block: %d data : 0x%08X", block, data);

View file

@ -197,7 +197,6 @@ local function ValidateCheckSums(blocks)
calc = CalcCheckSum(blocks,2,3) calc = CalcCheckSum(blocks,2,3)
if crc == calc then isOk='Ok' else isOk = 'Error' end if crc == calc then isOk='Ok' else isOk = 'Error' end
io.write( ('TYPE 3 area 2: %04x = %04x -- %s\n'):format(crc,calc,isOk)) io.write( ('TYPE 3 area 2: %04x = %04x -- %s\n'):format(crc,calc,isOk))
end
local cmd local cmd
local blockdata local blockdata