From edaf10af99156022f7719c6853812005579c8726 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 9 Nov 2015 21:51:34 +0100 Subject: [PATCH] CHG: minor code clean up, removed commented old code. ADD: usb_poll_validate_length to some deviceside loops. ADD: @marshmellow42 's fixes to LF --- armsrc/legicrf.c | 104 ++++++++++++++++++++++---------------------- armsrc/lfops.c | 19 ++++++-- armsrc/lfsampling.c | 4 +- client/cmddata.c | 6 +-- 4 files changed, 69 insertions(+), 64 deletions(-) diff --git a/armsrc/legicrf.c b/armsrc/legicrf.c index 68d4e760..d9c94106 100644 --- a/armsrc/legicrf.c +++ b/armsrc/legicrf.c @@ -81,38 +81,39 @@ static void setup_timer(void) /* Generate Keystream */ static uint32_t get_key_stream(int skip, int count) { - uint32_t key=0; int i; - - /* Use int to enlarge timer tc to 32bit */ - legic_prng_bc += prng_timer->TC_CV; - prng_timer->TC_CCR = AT91C_TC_SWTRG; - - /* If skip == -1, forward prng time based */ - if(skip == -1) { - i = (legic_prng_bc+SIM_SHIFT)/SIM_DIVISOR; /* Calculate Cycles based on timer */ - i -= legic_prng_count(); /* substract cycles of finished frames */ - i -= count; /* substract current frame length, rewidn to bedinning */ - legic_prng_forward(i); - } else { - legic_prng_forward(skip); - } + uint32_t key=0; int i; + + /* Use int to enlarge timer tc to 32bit */ + legic_prng_bc += prng_timer->TC_CV; + prng_timer->TC_CCR = AT91C_TC_SWTRG; + + /* If skip == -1, forward prng time based */ + if(skip == -1) { + i = (legic_prng_bc+SIM_SHIFT)/SIM_DIVISOR; /* Calculate Cycles based on timer */ + i -= legic_prng_count(); /* substract cycles of finished frames */ + i -= count; /* substract current frame length, rewidn to bedinning */ + legic_prng_forward(i); + } else { + legic_prng_forward(skip); + } - /* Write Time Data into LOG */ - uint8_t *BigBuf = BigBuf_get_addr(); - if(count == 6) { i = -1; } else { i = legic_read_count; } - BigBuf[OFFSET_LOG+128+i] = legic_prng_count(); - BigBuf[OFFSET_LOG+256+i*4] = (legic_prng_bc >> 0) & 0xff; - BigBuf[OFFSET_LOG+256+i*4+1] = (legic_prng_bc >> 8) & 0xff; - BigBuf[OFFSET_LOG+256+i*4+2] = (legic_prng_bc >>16) & 0xff; - BigBuf[OFFSET_LOG+256+i*4+3] = (legic_prng_bc >>24) & 0xff; - BigBuf[OFFSET_LOG+384+i] = count; - - /* Generate KeyStream */ - for(i=0; i> 0) & 0xff; + BigBuf[OFFSET_LOG+256+i*4+1] = (legic_prng_bc >> 8) & 0xff; + BigBuf[OFFSET_LOG+256+i*4+2] = (legic_prng_bc >>16) & 0xff; + BigBuf[OFFSET_LOG+256+i*4+3] = (legic_prng_bc >>24) & 0xff; + BigBuf[OFFSET_LOG+384+i] = count; + + /* Generate KeyStream */ + for(i=0; iTC_CV + TAG_TIME_BIT; int bit = response & 1; response = response >> 1; - if(bit) { + if(bit) AT91C_BASE_PIOA->PIO_SODR = GPIO_SSC_DOUT; - } else { + else AT91C_BASE_PIOA->PIO_CODR = GPIO_SSC_DOUT; - } + while(timer->TC_CV < nextbit) ; } AT91C_BASE_PIOA->PIO_CODR = GPIO_SSC_DOUT; @@ -171,11 +172,11 @@ static void frame_send_rwd(uint32_t data, int bits) int bit = data & 1; data = data >> 1; - if(bit ^ legic_prng_get_bit()) { + if(bit ^ legic_prng_get_bit()) bit_end = starttime + RWD_TIME_1; - } else { + else bit_end = starttime + RWD_TIME_0; - } + /* RWD_TIME_PAUSE time off, then some time on, so that the complete bit time is * RWD_TIME_x, where x is the bit to be transmitted */ @@ -184,16 +185,15 @@ static void frame_send_rwd(uint32_t data, int bits) AT91C_BASE_PIOA->PIO_SODR = GPIO_SSC_DOUT; legic_prng_forward(1); /* bit duration is longest. use this time to forward the lfsr */ - while(timer->TC_CV < bit_end) ; + while(timer->TC_CV < bit_end); } - { - /* One final pause to mark the end of the frame */ - int pause_end = timer->TC_CV + RWD_TIME_PAUSE; - AT91C_BASE_PIOA->PIO_CODR = GPIO_SSC_DOUT; - while(timer->TC_CV < pause_end) ; - AT91C_BASE_PIOA->PIO_SODR = GPIO_SSC_DOUT; - } + /* One final pause to mark the end of the frame */ + int pause_end = timer->TC_CV + RWD_TIME_PAUSE; + AT91C_BASE_PIOA->PIO_CODR = GPIO_SSC_DOUT; + while(timer->TC_CV < pause_end) ; + AT91C_BASE_PIOA->PIO_SODR = GPIO_SSC_DOUT; + /* Reset the timer, to measure time until the start of the tag frame */ timer->TC_CCR = AT91C_TC_SWTRG; @@ -239,8 +239,7 @@ static void frame_receive_rwd(struct legic_frame * const f, int bits, int crypt) * since we cannot compute it on the fly while reading */ legic_prng_forward(2); - if(crypt) - { + if(crypt) { for(i=0; ibits >= 31) { + if(f->bits >= 31) return; /* Overflow, won't happen */ - } + f->data |= (bit<bits); f->bits++; } @@ -448,12 +447,11 @@ int LegicRfReader(int offset, int bytes) { Dbprintf("Unknown card format: %x",tag_type); return -1; } - if(bytes == -1) { + if(bytes == -1) bytes = card_sz; - } - if(bytes+offset >= card_sz) { + + if(bytes+offset >= card_sz) bytes = card_sz-offset; - } perform_setup_phase_rwd(SESSION_IV); diff --git a/armsrc/lfops.c b/armsrc/lfops.c index b509b5a9..8e3a0dfe 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -1304,6 +1304,9 @@ void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT) { // load chip config block data[0] = T55x7_BITRATE_RF_50 | T55x7_MODULATION_FSK2a | last_block << T55x7_MAXBLOCK_SHIFT; + //TODO add selection of chip for Q5 or T55x7 + // data[0] = (((50-2)/2)<>32, id & 0xFFFFFFFF}; - if (card) { + clock = (card & 0xFF00) >> 8; clock = (clock == 0) ? 64 : clock; Dbprintf("Clock rate: %d", clock); + if (card & 0xFF) { //t55x7 clock = GetT55xxClockBit(clock); if (clock == 0) { Dbprintf("Invalid clock rate: %d", clock); return; } - data[0] = clock | T55x7_MODULATION_MANCHESTER | (2 << T55x7_MAXBLOCK_SHIFT); - } else { - data[0] = (0x1F << T5555_BITRATE_SHIFT) | T5555_MODULATION_MANCHESTER | (2 << T5555_MAXBLOCK_SHIFT); + } else { //t5555 (Q5) + clock = (clock-2)>>1; //n = (RF-2)/2 + data[0] = (clock << T5555_BITRATE_SHIFT) | T5555_MODULATION_MANCHESTER | (2 << T5555_MAXBLOCK_SHIFT); } WriteT55xx(data, 0, 3); diff --git a/armsrc/lfsampling.c b/armsrc/lfsampling.c index ab3a187f..6eecf407 100644 --- a/armsrc/lfsampling.c +++ b/armsrc/lfsampling.c @@ -141,7 +141,7 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag uint32_t sample_total_numbers =0 ; uint32_t sample_total_saved =0 ; - while(!BUTTON_PRESS()) { + while(!BUTTON_PRESS() && !usb_poll_validate_length() ) { WDT_HIT(); if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) { AT91C_BASE_SSC->SSC_THR = 0x43; @@ -269,7 +269,7 @@ void doT55x7Acquisition(size_t sample_size) { uint8_t curSample = 0; uint8_t firstSample = 0; uint16_t skipCnt = 0; - while(!BUTTON_PRESS() && skipCnt<1000) { + while(!BUTTON_PRESS() && !usb_poll_validate_length() && skipCnt<1000) { WDT_HIT(); if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) { AT91C_BASE_SSC->SSC_THR = 0x43; diff --git a/client/cmddata.c b/client/cmddata.c index e955fec7..f4b596aa 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -1220,10 +1220,6 @@ int CmdFSKdemodIO(const char *Cmd) //print full AWID Prox ID and some bit format details if found int CmdFSKdemodAWID(const char *Cmd) { - - //int verbose=1; - //sscanf(Cmd, "%i", &verbose); - //raw fsk demod no manchester decoding no start bit finding just get binary from wave uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0}; size_t size = getFromGraphBuf(BitStream); @@ -1254,7 +1250,7 @@ int CmdFSKdemodAWID(const char *Cmd) // | | | | | | | // 01234567 890 1 234 5 678 9 012 3 456 7 890 1 234 5 678 9 012 3 456 7 890 1 234 5 678 9 012 3 - to 96 // ----------------------------------------------------------------------------- - // 00000001 000 1 110 1 101 1 011 1 101 1 010 0 000 1 000 1 010 0 001 0 110 1 100 0 000 1 000 1 + // 00000001 000 1 110 1 101 1 011 1 1 d01 1 010 0 000 1 000 1 010 0 001 0 110 1 100 0 000 1 000 1 // premable bbb o bbb o bbw o fff o fff o ffc o ccc o ccc o ccc o ccc o ccc o wxx o xxx o xxx o - to 96 // |---26 bit---| |-----117----||-------------142-------------| // b = format bit len, o = odd parity of last 3 bits -- 2.39.5