]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
CHG: minor code clean up, removed commented old code.
authoriceman1001 <iceman@iuse.se>
Mon, 9 Nov 2015 20:51:34 +0000 (21:51 +0100)
committericeman1001 <iceman@iuse.se>
Mon, 9 Nov 2015 20:51:34 +0000 (21:51 +0100)
ADD: usb_poll_validate_length  to some deviceside loops.
ADD: @marshmellow42 's fixes to LF

armsrc/legicrf.c
armsrc/lfops.c
armsrc/lfsampling.c
client/cmddata.c

index 68d4e7600356df9f6520cd9809deb14c6ebadde6..d9c94106e2f0fec21deede3e6d23fcd0e04455ad 100644 (file)
@@ -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<count; i++) {
-    key |= legic_prng_get_bit() << i;
-    legic_prng_forward(1);
-  }
-  return key;
+       /* Write Time Data into LOG */
+       uint8_t *BigBuf = BigBuf_get_addr();
+       i = (count == 6) ? -1 : 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<count; i++) {
+               key |= legic_prng_get_bit() << i;
+               legic_prng_forward(1);
+       }
+       return key;
 }
 
 /* Send a frame in tag mode, the FPGA must have been set up by
@@ -145,11 +146,11 @@ static void frame_send_tag(uint16_t response, int bits, int crypt)
       int nextbit = timer->TC_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; i<bits; i++) {
                        data |= legic_prng_get_bit() << i;
                        legic_prng_forward(1);
@@ -277,9 +276,9 @@ static void frame_receive_rwd(struct legic_frame * const f, int bits, int crypt)
 
 static void frame_append_bit(struct legic_frame * const f, int bit)
 {
-   if(f->bits >= 31) {
+   if(f->bits >= 31)
        return; /* Overflow, won't happen */
-   }
+  
    f->data |= (bit<<f->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);
 
index b509b5a9e2b067bb5bda82915ef9a7403ffc8add..8e3a0dfedf2ea49b5cc240ae7f7d7981b942b0fa 100644 (file)
@@ -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)<<T5555_BITRATE_SHIFT) | T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | last_block << T5555_MAXBLOCK_SHIFT;
+
        LED_D_ON();
        // Program the data blocks for supplied ID
        // and the block 0 for HID format
@@ -1316,6 +1319,8 @@ void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT) {
 
 void CopyIOtoT55x7(uint32_t hi, uint32_t lo) {
        uint32_t data[] = {T55x7_BITRATE_RF_64 | T55x7_MODULATION_FSK2a | (2 << T55x7_MAXBLOCK_SHIFT), hi, lo};
+       //TODO add selection of chip for Q5 or T55x7
+       // data[0] = (((64-2)/2)<<T5555_BITRATE_SHIFT) | T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | 2 << T5555_MAXBLOCK_SHIFT;
 
        LED_D_ON();
        // Program the data blocks for supplied ID
@@ -1332,6 +1337,9 @@ void CopyIndala64toT55x7(uint32_t hi, uint32_t lo) {
        //Program the 2 data blocks for supplied 64bit UID
        // and the Config for Indala 64 format (RF/32;PSK1 with RF/2;Maxblock=2)
        uint32_t data[] = { T55x7_BITRATE_RF_32 | T55x7_MODULATION_PSK1 | (2 << T55x7_MAXBLOCK_SHIFT), hi, lo};
+       //TODO add selection of chip for Q5 or T55x7
+       // data[0] = (((32-2)/2)<<T5555_BITRATE_SHIFT) | T5555_MODULATION_PSK1 | 2 << T5555_MAXBLOCK_SHIFT;
+
        WriteT55xx(data, 0, 3);
        //Alternative config for Indala (Extended mode;RF/32;PSK1 with RF/2;Maxblock=2;Inverse data)
        //      T5567WriteBlock(0x603E1042,0);
@@ -1344,6 +1352,8 @@ void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t
        // and the block 0 for Indala224 format 
        //Config for Indala (RF/32;PSK1 with RF/2;Maxblock=7)
        data[0] = T55x7_BITRATE_RF_32 | T55x7_MODULATION_PSK1 | (7 << T55x7_MAXBLOCK_SHIFT);
+       //TODO add selection of chip for Q5 or T55x7
+       // data[0] = (((32-2)/2)<<T5555_BITRATE_SHIFT) | T5555_MODULATION_PSK1 | 7 << T5555_MAXBLOCK_SHIFT;
        WriteT55xx(data, 0, 8);
        //Alternative config for Indala (Extended mode;RF/32;PSK1 with RF/2;Maxblock=7;Inverse data)
        //      T5567WriteBlock(0x603E10E2,0);
@@ -1415,19 +1425,20 @@ void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo) {
 
        // Write EM410x ID
        uint32_t data[] = {0, id>>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);
index ab3a187fa7d68d61bf91cc6107880034ba9f8db1..6eecf4075ebf82a94cd6324e3afb4721e76376e2 100644 (file)
@@ -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;
index e955fec7e9fe1cdd29be0ebf04502b36e8709025..f4b596aabe757b3f12efc93023cc85596b6fcfc2 100644 (file)
@@ -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
Impressum, Datenschutz