]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/lfops.c
ADD: AWID 50bit demod
[proxmark3-svn] / armsrc / lfops.c
index 7f61c78dcce1d951b5ae3eaa3a843e6a5e9de8f0..69b76d1215ab624ad0baf27575841d4ad6fb11a5 100644 (file)
@@ -270,7 +270,7 @@ void AcquireTiType(void)
        AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(32) | AT91C_SSC_MSBF;
        AT91C_BASE_SSC->SSC_TCMR = 0;
        AT91C_BASE_SSC->SSC_TFMR = 0;
-
+       // iceman, FpgaSetupSsc() ?? the code above? can it be replaced?
        LED_D_ON();
 
        // modulate antenna
@@ -380,7 +380,7 @@ void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc)
        AcquireTiType();
 
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
-       DbpString("Now use 'lf ti read' to check");
+       DbpString("Now use `lf ti read` to check");
 }
 
 void SimulateTagLowFrequency(int period, int gap, int ledcontrol)
@@ -628,7 +628,19 @@ static void biphaseSimBit(uint8_t c, int *n, uint8_t clock, uint8_t *phase)
                memset(dest+(*n), c ^ *phase, clock);
                *phase ^= 1;
        }
+       *n += clock;
+}
 
+static void stAskSimBit(int *n, uint8_t clock) {
+       uint8_t *dest = BigBuf_get_addr();
+       uint8_t halfClk = clock/2;
+       //ST = .5 high .5 low 1.5 high .5 low 1 high    
+       memset(dest+(*n), 1, halfClk);
+       memset(dest+(*n) + halfClk, 0, halfClk);
+       memset(dest+(*n) + clock, 1, clock + halfClk);
+       memset(dest+(*n) + clock*2 + halfClk, 0, halfClk);
+       memset(dest+(*n) + clock*3, 1, clock);
+       *n += clock*4;
 }
 
 // args clock, ask/man or askraw, invert, transmission separator
@@ -646,7 +658,7 @@ void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
                for (i=0; i<size; i++){
                        biphaseSimBit(BitStream[i]^invert, &n, clk, &phase);
                }
-               if (BitStream[0]==BitStream[size-1]){ //run a second set inverted to keep phase in check
+               if (phase==1) { //run a second set inverted to keep phase in check
                        for (i=0; i<size; i++){
                                biphaseSimBit(BitStream[i]^invert, &n, clk, &phase);
                        }
@@ -661,8 +673,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 && encoding == 1)
+               stAskSimBit(&n, clk);
+       else 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);
 
@@ -856,7 +870,6 @@ void CmdAWIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
 
                size = removeParity(dest, idx+8, 4, 1, 88);
                if (size != 66) continue;
-               // ok valid card found!
 
                // Index map
                // 0           10         20        30          40        50        60
@@ -866,37 +879,51 @@ void CmdAWIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
                // 00011010 1 01110101 0000000010001110 1 000000000000000000000000000000000
                // bbbbbbbb w ffffffff cccccccccccccccc w xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                // |26 bit|   |-117--| |-----142------|
+                       //
+                       // 00110010 0 0000011111010000000000000001000100101000100001111 0 00000000 
+                       // bbbbbbbb w ffffffffffffffffccccccccccccccccccccccccccccccccc w xxxxxxxx
+                       // |50 bit|   |----4000------||-----------2248975-------------|                         
+                       //
                // b = format bit len, o = odd parity of last 3 bits
                // f = facility code, c = card number
                // w = wiegand parity
-               // (26 bit format shown)
 
                uint32_t fc = 0;
                uint32_t cardnum = 0;
                uint32_t code1 = 0;
                uint32_t code2 = 0;
                uint8_t fmtLen = bytebits_to_byte(dest,8);
-               if (fmtLen==26){
-                       fc = bytebits_to_byte(dest+9, 8);
-                       cardnum = bytebits_to_byte(dest+17, 16);
-                       code1 = bytebits_to_byte(dest+8,fmtLen);
-                       Dbprintf("AWID Found - BitLength: %d, FC: %d, Card: %d - Wiegand: %x, Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, rawHi2, rawHi, rawLo);
-               } else {
-                       cardnum = bytebits_to_byte(dest+8+(fmtLen-17), 16);
-                       if (fmtLen>32){
-                        code1 = bytebits_to_byte(dest+8,fmtLen-32);
-                        code2 = bytebits_to_byte(dest+8+(fmtLen-32),32);
-                        Dbprintf("AWID Found - BitLength: %d -unknown BitLength- (%d) - Wiegand: %x%08x, Raw: %08x%08x%08x", fmtLen, cardnum, code1, code2, rawHi2, rawHi, rawLo);
-                } else{
-                        code1 = bytebits_to_byte(dest+8,fmtLen);
-                        Dbprintf("AWID Found - BitLength: %d -unknown BitLength- (%d) - Wiegand: %x, Raw: %08x%08x%08x", fmtLen, cardnum, code1, rawHi2, rawHi, rawLo);
-                }
+                       switch(fmtLen) {
+                               case 26: 
+                                       fc = bytebits_to_byte(dest + 9, 8);
+                                       cardnum = bytebits_to_byte(dest + 17, 16);
+                                       code1 = bytebits_to_byte(dest + 8,fmtLen);
+                                       Dbprintf("AWID Found - BitLength: %d, FC: %d, Card: %d - Wiegand: %x, Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, rawHi2, rawHi, rawLo);
+                                       break;
+                               case 50:
+                                       fc = bytebits_to_byte(dest + 9, 16);
+                                       cardnum = bytebits_to_byte(dest + 25, 32);
+                                       code1 = bytebits_to_byte(dest + 8, (fmtLen-32) );
+                                       code2 = bytebits_to_byte(dest + 8 + (fmtLen-32), 32);
+                                       Dbprintf("AWID Found - BitLength: %d, FC: %d, Card: %d - Wiegand: %x%08x, Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo);
+                                       break;
+                               default:
+                                       if (fmtLen > 32 ) {
+                                               cardnum = bytebits_to_byte(dest+8+(fmtLen-17), 16);
+                                               code1 = bytebits_to_byte(dest+8,fmtLen-32);
+                                               code2 = bytebits_to_byte(dest+8+(fmtLen-32),32);
+                                               Dbprintf("AWID Found - BitLength: %d -unknown BitLength- (%d) - Wiegand: %x%08x, Raw: %08x%08x%08x", fmtLen, cardnum, code1, code2, rawHi2, rawHi, rawLo);
+                                       } else {
+                                               cardnum = bytebits_to_byte(dest+8+(fmtLen-17), 16);
+                                               code1 = bytebits_to_byte(dest+8,fmtLen);
+                                               Dbprintf("AWID Found - BitLength: %d -unknown BitLength- (%d) - Wiegand: %x, Raw: %08x%08x%08x", fmtLen, cardnum, code1, rawHi2, rawHi, rawLo);
+                                       }
+                                       break;          
                        }
                        if (findone){
                                if (ledcontrol) LED_A_OFF();
                                return;
                        }
-                       // reset
                idx = 0;
                WDT_HIT();
        }
@@ -1431,7 +1458,7 @@ void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo) {
        LED_D_ON();
 
        // Write EM410x ID
-       uint32_t data[] = {0, (uint32_t)(id>>32), id & 0xFFFFFFFF};
+       uint32_t data[] = {0, (uint32_t)(id>>32), (uint32_t)(id & 0xFFFFFFFF)};
 
        clock = (card & 0xFF00) >> 8;
        clock = (clock == 0) ? 64 : clock;
Impressum, Datenschutz