]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
FIX: T5555/Q5 datarate when used in "Q" parameter, consequential fix in lf commands...
authoriceman1001 <iceman@iuse.se>
Mon, 13 Feb 2017 09:58:28 +0000 (10:58 +0100)
committericeman1001 <iceman@iuse.se>
Mon, 13 Feb 2017 09:58:28 +0000 (10:58 +0100)
ADD: Marshmellow42 's timing fixes for em4305.

12 files changed:
armsrc/lfops.c
client/cmdlfawid.c
client/cmdlfem4x.c
client/cmdlffdx.c
client/cmdlfguard.c
client/cmdlfio.c
client/cmdlfjablotron.c
client/cmdlfnedap.c
client/cmdlfnoralsy.c
client/cmdlfpresco.c
client/cmdlfpyramid.c
client/cmdlfvisa2000.c

index 28b8b5df99b6e43a253cd0692cc5aebdb07b380b..c8eed468c5ebd6e294556b1365f2b84f2c910601 100644 (file)
@@ -710,7 +710,7 @@ void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
                for (i=0; i<size; i++){
                        askSimBit(BitStream[i]^invert, &n, clk, encoding);
                }
-               if (encoding==0 && BitStream[0]==BitStream[size-1]){ //run a second set inverted (for biphase phase)
+               if (encoding==0 && BitStream[0]==BitStream[size-1]){ //run a second set inverted (for ask/raw || biphase phase)
                        for (i=0; i<size; i++){
                                askSimBit(BitStream[i]^invert^1, &n, clk, encoding);
                        }
@@ -1388,7 +1388,7 @@ void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT) {
        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;
+       // data[0] = (((50-2)>>1)<<T5555_BITRATE_SHIFT) | T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | last_block << T5555_MAXBLOCK_SHIFT;
 
        LED_D_ON();
        WriteT55xx(data, 0, last_block+1);
@@ -1399,7 +1399,7 @@ 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
        //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
-       // data[0] = (64 << T5555_BITRATE_SHIFT) | T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | 2 << T5555_MAXBLOCK_SHIFT;
+       // data[0] = ( ((64-2)>>1) << T5555_BITRATE_SHIFT) | T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | 2 << T5555_MAXBLOCK_SHIFT;
 
        LED_D_ON();
        // Program the data blocks for supplied ID
@@ -1414,7 +1414,7 @@ void CopyIndala64toT55x7(uint32_t hi, uint32_t lo) {
        // 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;
+       // data[0] = (((32-2)>>1)<<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)
@@ -1428,7 +1428,7 @@ void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t
        //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;
+       // data[0] = (((32-2)>>1) << 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);
@@ -1437,7 +1437,7 @@ void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t
 void CopyVikingtoT55xx(uint32_t block1, uint32_t block2, uint8_t Q5) {
        uint32_t data[] = {T55x7_BITRATE_RF_32 | T55x7_MODULATION_MANCHESTER | (2 << T55x7_MAXBLOCK_SHIFT), block1, block2};
        //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
-       if (Q5) data[0] = (32 << T5555_BITRATE_SHIFT) | T5555_MODULATION_MANCHESTER | 2 << T5555_MAXBLOCK_SHIFT;
+       if (Q5) data[0] = (((32-2)>>1) << T5555_BITRATE_SHIFT) | T5555_MODULATION_MANCHESTER | 2 << T5555_MAXBLOCK_SHIFT;
        // Program the data blocks for supplied ID and the block 0 config
        WriteT55xx(data, 0, 3);
        LED_D_OFF();
@@ -1521,8 +1521,8 @@ void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo) {
                }
                data[0] = clock | T55x7_MODULATION_MANCHESTER | (2 << T55x7_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);
+               // t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
+               data[0] = ( ((clock-2) >> 1) << T5555_BITRATE_SHIFT) | T5555_MODULATION_MANCHESTER | (2 << T5555_MAXBLOCK_SHIFT);
        }
  
        WriteT55xx(data, 0, 3);
@@ -1648,7 +1648,7 @@ void SendForward(uint8_t fwd_bit_count) {
 // 16FC * 8us == 128us / 21.3 ==  6.009 steps. ok 
 
 #ifndef EM_START_GAP
-#define EM_START_GAP 56*8
+#define EM_START_GAP 60*8
 #endif
 #ifndef EM_ONE_GAP
 #define EM_ONE_GAP 32*8
@@ -1669,8 +1669,7 @@ void SendForward(uint8_t fwd_bit_count) {
        
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
        WaitUS(EM_START_GAP);
-
-       TurnReadLFOn(EM_ZERO_GAP);
+       TurnReadLFOn(16);
 
        // now start writting with bitbanging the antenna.
        while(fwd_bit_sz-- > 0) { //prepare next bit modulation
@@ -1679,8 +1678,8 @@ void SendForward(uint8_t fwd_bit_count) {
                else {
                        //These timings work for 4469/4269/4305
                        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
-                       WaitUS(EM_ZERO_GAP);                    
-                       TurnReadLFOn(EM_ZERO_GAP);
+                       WaitUS(20);                     
+                       TurnReadLFOn(12);
                }
        }
 }
@@ -1691,7 +1690,10 @@ void EM4xLogin(uint32_t pwd) {
        len = Prepare_Cmd( FWD_CMD_LOGIN );
        len += Prepare_Data( pwd & 0xFFFF, pwd >> 16 );
        SendForward(len);
-       WaitMS(20);
+       //WaitMS(20); - no wait for login command.
+       // should receive
+       // 0000 1010 ok.
+       // 0000 0001 fail
 }
 
 void EM4xReadWord(uint8_t addr, uint32_t pwd, uint8_t usepwd) {
@@ -1703,6 +1705,12 @@ void EM4xReadWord(uint8_t addr, uint32_t pwd, uint8_t usepwd) {
        //clear buffer now so it does not interfere with timing later
        BigBuf_Clear_ext(false);
        
+       /* should we read answer from Logincommand?
+       *
+       * should receive
+       * 0000 1010 ok.
+       * 0000 0001 fail
+       **/
        if (usepwd) EM4xLogin(pwd);
 
        forward_ptr = forwardLink_data;
@@ -1728,7 +1736,13 @@ void EM4xWriteWord(uint32_t flag, uint32_t data, uint32_t pwd) {
        
        //clear buffer now so it does not interfere with timing later
        BigBuf_Clear_ext(false);
-       
+
+       /* should we read answer from Logincommand?
+       *
+       * should receive
+       * 0000 1010 ok.
+       * 0000 0001 fail
+       **/     
        if (usePwd) EM4xLogin(pwd);
 
        forward_ptr = forwardLink_data;
index db2614aa5561071dc13818ba40123bbc918fb25b..9883437a759c93824656172c685fc86611e51a7f 100644 (file)
@@ -281,9 +281,9 @@ int CmdAWIDClone(const char *Cmd) {
 
        if ( !fc || !cn) return usage_lf_awid_clone();
        
-       if (param_getchar(Cmd, 4) == 'Q' || param_getchar(Cmd, 4) == 'q')
+       if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q')
                //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
-               blocks[0] = T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | 50<<T5555_BITRATE_SHIFT | 3<<T5555_MAXBLOCK_SHIFT;
+               blocks[0] = T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | ((50-2)>>1) << T5555_BITRATE_SHIFT | 3<<T5555_MAXBLOCK_SHIFT;
 
        verify_values(&fmtlen, &fc, &cn);
                
index 2cf8f569d3958d4d9380739df3345f3ff16e6545..636d2596b29609b740ae1a1b0cbefdabb4ed1e90 100644 (file)
@@ -283,7 +283,7 @@ uint32_t OutputEM4x50_Block(uint8_t *BitStream, size_t size, bool verbose, bool
        }
        return code;
 }
-/* Read the transmitted data of an EM4x50 tag
+/* Read the transmitted data of an EM4x50 tag from the graphbuffer
  * Format:
  *
  *  XXXXXXXX [row parity bit (even)] <- 8 bits plus parity
@@ -305,19 +305,7 @@ uint32_t OutputEM4x50_Block(uint8_t *BitStream, size_t size, bool verbose, bool
  //completed by Marshmellow
 int EM4x50Read(const char *Cmd, bool verbose)
 {
-       /*
-       char buf[30] = {0x00};
-       char *cmdStr = buf;
-       int ans = 0;
-       bool ST = config.ST;
-       uint8_t bitRate[8] = {8,16,32,40,50,64,100,128};
-       DemodBufferLen = 0x00;  
-       snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );
-       ans = ASKDemod_ext(cmdStr, FALSE, FALSE, 1, &ST);
-       snprintf(cmdStr, sizeof(buf),"0 %d %d 1", bitRate[config.bitrate], config.inverted );
-       ans = ASKbiphaseDemod(cmdStr, FALSE);
-       */
-       
+
        uint8_t fndClk[] = {8,16,32,40,50,64,128};
        int clk = 0; 
        int invert = 0;
@@ -553,14 +541,46 @@ int CmdReadWord(const char *Cmd) {
                return -1;
        }
        
-       //uint8_t got[12288];
-       uint8_t got[30000];
+       uint8_t got[6000];
        GetFromBigBuf(got, sizeof(got), 0);
-       if ( !WaitForResponseTimeout(CMD_ACK, NULL, 8000) ) {
+       if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2500) ) {
                PrintAndLog("command execution time out");
-               return 0;
+               return -1;
        }
        setGraphBuf(got, sizeof(got));
+       
+       
+       int ans = 0;
+       //bool ST = true;
+       DemodBufferLen = 0x00;  
+
+       //ans = ASKDemod_ext("0 0 1", FALSE, FALSE, 1, &ST);
+       ans = ASKbiphaseDemod("0 0 1", FALSE);
+       if (!ans) { 
+               if (g_debugMode) PrintAndLog("DEBUG: Error - EM4305: ASK/Manchester Demod failed");
+               return -1;
+       }
+
+       size_t startIdx = 0, size = DemodBufferLen; 
+
+       PrintAndLog("ANS: %d | %u | %u", ans, startIdx, size);
+
+       
+       uint8_t preamble[8] = {0,0,0,0,1,0,1,0};        
+       uint8_t errChk = !preambleSearch(DemodBuffer, preamble, sizeof(preamble), &size, &startIdx);
+       if ( errChk == 0) {
+               if (g_debugMode) PrintAndLog("DEBUG: Error - EM4305 preamble not found :: %d", startIdx);
+               return -1;
+       }
+
+       // sanity check. 
+       if (size != 32) {
+               if (g_debugMode) PrintAndLog("DEBUG: Error - EM4305 incorrect data length found,  %u", size );
+               return -1;
+       }
+
+       //setDemodBuf(BitStream, 32, preambleIndex);
+       
        return 1;
 }
 
@@ -614,6 +634,37 @@ int CmdWriteWord(const char *Cmd) {
                PrintAndLog("Error occurred, device did not respond during write operation.");
                return -1;
        }
+       
+       //get response if there is one
+       uint8_t got[6000]; // 8 bit preamble + 32 bit word response (max clock (128) * 40bits = 5120 samples)
+       GetFromBigBuf(got, sizeof(got), 0);
+       if ( !WaitForResponseTimeout(CMD_ACK, NULL, 8000) ) {
+               PrintAndLog("command execution time out");
+               return -2;
+       }
+       setGraphBuf(got, sizeof(got));
+       
+       int ans = 0;
+       //bool ST = true;
+       DemodBufferLen = 0x00;  
+
+       //ans = ASKDemod_ext("0 0 1", FALSE, FALSE, 1, &ST);
+       ans = ASKbiphaseDemod("0 0 1", FALSE);
+       if (!ans) { 
+               if (g_debugMode) PrintAndLog("DEBUG: Error - EM4305: ASK/Manchester Demod failed");
+               return -3;
+       }
+       PrintAndLog("ANS: %d", ans);
+       
+       //todo: check response for 00001010 then write data for write confirmation!     
+       size_t startIdx = 0, size = DemodBufferLen; 
+
+       uint8_t preamble[8] = {0,0,0,0,1,0,1,0};                
+       if (!preambleSearch(DemodBuffer, preamble, sizeof(preamble), &size, &startIdx)){
+               if (g_debugMode) PrintAndLog("DEBUG: Error - EM4305 preamble not found :: %d", startIdx);
+               return -4;
+       }
+       PrintAndLog("Write OK");
        return 0;
 }
 
@@ -625,9 +676,9 @@ static command_t CommandTable[] = {
        {"em410xwatch", CmdEM410xWatch,         0, "['h'] -- Watches for EM410x 125/134 kHz tags (option 'h' for 134)"},
        {"em410xspoof", CmdEM410xWatchnSpoof, 0, "['h'] --- Watches for EM410x 125/134 kHz tags, and replays them. (option 'h' for 134)" },
        {"em410xwrite", CmdEM410xWrite,         0, "<UID> <'0' T5555> <'1' T55x7> [clock rate] -- Write EM410x UID to T5555(Q5) or T55x7 tag, optionally setting clock rate"},
-       {"em4x50read",  CmdEM4x50Read,          1, "Extract data from EM4x50 tag"},
-       {"readword",    CmdReadWord,            1, "Read EM4xxx data"},
-       {"writeword",   CmdWriteWord,           1, "Write EM4xxx data"},
+       {"em4x50read",  CmdEM4x50Read,          1, "demod data from EM4x50 tag from the graphbuffer"},
+       {"readword",    CmdReadWord,            1, "read EM4x05/4x69 data"},
+       {"writeword",   CmdWriteWord,           1, "write EM405/4x69 data"},
        {NULL, NULL, 0, NULL}
 };
 
index 0e6b43f48d2dfb95ca5fe542568ef3470ea0a2f3..292ebad6617e1a5472b5d7638688051121ace189 100644 (file)
@@ -202,7 +202,7 @@ int CmdFdxClone(const char *Cmd) {
 
        uint32_t countryid = 0;
        uint64_t animalid = 0;
-       uint32_t blocks[5] = {T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_32 | 4<<T55x7_MAXBLOCK_SHIFT, 0, 0, 0, 0};
+       uint32_t blocks[5] = {T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_32 | 4 << T55x7_MAXBLOCK_SHIFT, 0, 0, 0, 0};
        uint8_t bits[128];
        uint8_t *bs = bits;
        memset(bs, 0, sizeof(bits));
@@ -214,9 +214,9 @@ int CmdFdxClone(const char *Cmd) {
        animalid = param_get64ex(Cmd, 1, 0, 10);
        
        //Q5
-       if (param_getchar(Cmd, 1) == 'Q' || param_getchar(Cmd, 1) == 'q') {
+       if (param_getchar(Cmd, 2) == 'Q' || param_getchar(Cmd, 2) == 'q') {
                //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
-               blocks[0] = T5555_MODULATION_BIPHASE | T5555_INVERT_OUTPUT | 32<<T5555_BITRATE_SHIFT | 4<<T5555_MAXBLOCK_SHIFT;
+               blocks[0] = T5555_MODULATION_BIPHASE | T5555_INVERT_OUTPUT | ((32-2)>>1) << T5555_BITRATE_SHIFT | 4 << T5555_MAXBLOCK_SHIFT;
        }
        
        verify_values(countryid, animalid);
index d9010a19a2209e99045f4dab5ba84a3092500e04..ddfd29637da575fdbd634965ac7bd161f412fd22 100644 (file)
@@ -15,8 +15,9 @@ int usage_lf_guard_clone(void){
        PrintAndLog("The facility-code is 8-bit and the card number is 16-bit.  Larger values are truncated. ");
        PrintAndLog("Currently work only on 26bit");
        PrintAndLog("");
-       PrintAndLog("Usage: lf guard clone <Facility-Code> <Card-Number>");
+       PrintAndLog("Usage: lf guard clone <format> <Facility-Code> <Card-Number>");
        PrintAndLog("Options :");
+       PrintAndLog("         <format> :  format length 26|32|36|40");  
        PrintAndLog("  <Facility-Code> :  8-bit value facility code");
        PrintAndLog("  <Card Number>   : 16-bit value card number");
        PrintAndLog("");
@@ -30,8 +31,9 @@ int usage_lf_guard_sim(void) {
        PrintAndLog("The facility-code is 8-bit and the card number is 16-bit.  Larger values are truncated.");
        PrintAndLog("Currently work only on 26bit");
        PrintAndLog("");
-       PrintAndLog("Usage:  lf guard sim <Card-Number>");
+       PrintAndLog("Usage:  lf guard sim <format> <Card-Number>");
        PrintAndLog("Options :");
+       PrintAndLog("         <format> :  format length 26|32|36|40");  
        PrintAndLog("  <Facility-Code> :  8-bit value facility code");
        PrintAndLog("  <Card Number>   : 16-bit value card number");
        PrintAndLog("");
@@ -40,44 +42,61 @@ int usage_lf_guard_sim(void) {
 }
 
 // Works for 26bits.
-int GetGuardBits(uint32_t fc, uint32_t cn, uint8_t *guardBits) {
+int GetGuardBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *guardBits) {
   
-       // Intializes random number generator
-       time_t t;
-       srand((unsigned) time(&t));
-       //uint8_t xorKey = rand() % 0xFF;
        uint8_t xorKey = 0x66;
        uint8_t i;
        uint8_t pre[96];
+       uint8_t rawbytes[12];
        memset(pre, 0x00, sizeof(pre));
+       memset(rawbytes, 0x00, sizeof(rawbytes));       
 
-       // Get 26 wiegand from FacilityCode, CardNumber 
-       uint8_t wiegand[24];
-       memset(wiegand, 0x00, sizeof(wiegand));
-       num_to_bytebits(fc, 8, wiegand);
-       num_to_bytebits(cn, 16, wiegand+8);
-
-       // add wiegand parity bits (dest, source, len)
-       wiegand_add_parity(pre, wiegand, 24);
-
-       // lets start. 12bytes of data to be produced.
-       uint8_t rawbytes[12];
-       memset(rawbytes, 0x00, sizeof(rawbytes));
+       // add format length (decimal)
+       switch (fmtlen) {
+               case 32: {
+                       rawbytes[1] = (32 << 2);
+                       
+                       break;
+               }
+               case 36: {
+                       // FC = ((ByteStream[3] & 0x7F)<<7) | (ByteStream[4]>>1);
+                       // Card = ((ByteStream[4]&1)<<19) | (ByteStream[5]<<11) | (ByteStream[6]<<3) | (ByteStream[7]>>5);
+                       rawbytes[1] = (36 << 2);
+                       // Get 26 wiegand from FacilityCode, CardNumber 
+                       uint8_t wiegand[34];
+                       memset(wiegand, 0x00, sizeof(wiegand));
+                       num_to_bytebits(fc, 8, wiegand);
+                       num_to_bytebits(cn, 26, wiegand+8);
+
+                       // add wiegand parity bits (dest, source, len)
+                       wiegand_add_parity(pre, wiegand, 34);                   
+                       break;
+               }
+               case 40: {
+                       rawbytes[1] = (40 << 2);
+                       break;
+               }
+               case 26:
+               default: {
+                       rawbytes[1] = (26 << 2);
+                       // Get 26 wiegand from FacilityCode, CardNumber 
+                       uint8_t wiegand[24];
+                       memset(wiegand, 0x00, sizeof(wiegand));
+                       num_to_bytebits(fc, 8, wiegand);
+                       num_to_bytebits(cn, 16, wiegand+8);
+
+                       // add wiegand parity bits (dest, source, len)
+                       wiegand_add_parity(pre, wiegand, 24);
+                       break;
+               }
+       }
+       // 2bit checksum, unknown today, 
+       // these two bits are the last ones of rawbyte[1], hence the LSHIFT above.
 
+       
        // xor key
        rawbytes[0] = xorKey;
-
-       // add format length (decimal)
-       // len | hex | bin
-       //  26 | 1A  | 0001 1010
-       rawbytes[1] = (26 << 2);
-       //  36 | 24  | 0010 0100
-       //rawbytes[1] = (36 << 2);
-       //  40 | 28  | 0010 1000
-       //rawbytes[1] = (40 << 2);
        
-       // 2bit checksum, unknown today, 
-       // these two bits are the last ones of rawbyte[1], hence the LSHIFT above.
        rawbytes[2] = 1;
        rawbytes[3] = 0;
        
@@ -87,6 +106,7 @@ int GetGuardBits(uint32_t fc, uint32_t cn, uint8_t *guardBits) {
        
        if (g_debugMode) printf(" WIE | %s\n", sprint_hex(rawbytes, sizeof(rawbytes))); 
        
+       
        // XOR (only works on wiegand stuff)
        for (i = 1; i < 12; ++i)
                rawbytes[i] ^= xorKey ;
@@ -127,24 +147,25 @@ int CmdGuardClone(const char *Cmd) {
        char cmdp = param_getchar(Cmd, 0);
        if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_guard_clone();
 
-       uint32_t facilitycode=0, cardnumber=0, fc = 0, cn = 0;
+       uint32_t facilitycode = 0, cardnumber = 0, fc = 0, cn = 0, fmtlen = 0;
        uint8_t i;
        uint8_t bs[96];
        memset(bs, 0x00, sizeof(bs));
        
        //GuardProxII - compat mode, ASK/Biphase,  data rate 64, 3 data blocks
-       uint32_t blocks[5] = {T55x7_MODULATION_BIPHASE | T55x7_BITRATE_RF_64 | 3<<T55x7_MAXBLOCK_SHIFT, 0, 0, 0, 0};
+       uint32_t blocks[5] = {T55x7_MODULATION_BIPHASE | T55x7_BITRATE_RF_64 | 3 << T55x7_MAXBLOCK_SHIFT, 0, 0, 0, 0};
        
-//     if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q')
-       //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
-//             blocks[0] = T5555_MODULATION_FSK2 | 50<<T5555_BITRATE_SHIFT | 4<<T5555_MAXBLOCK_SHIFT;
+       if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q')
+               //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
+               blocks[0] = T5555_MODULATION_FSK2 | ((50-2)>>1) << T5555_BITRATE_SHIFT | 3 << T5555_MAXBLOCK_SHIFT;
 
-       if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) return usage_lf_guard_clone();
+       if (sscanf(Cmd, "%u %u %u", &fmtlen, &fc, &cn ) != 2) return usage_lf_guard_clone();
 
+       fmtlen &= 0x7f;
        facilitycode = (fc & 0x000000FF);
        cardnumber = (cn & 0x0000FFFF);
        
-       if ( !GetGuardBits(facilitycode, cardnumber, bs)) {
+       if ( !GetGuardBits(fmtlen, facilitycode, cardnumber, bs)) {
                PrintAndLog("Error with tag bitstream generation.");
                return 1;
        }       
@@ -180,18 +201,19 @@ int CmdGuardSim(const char *Cmd) {
        char cmdp = param_getchar(Cmd, 0);
        if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_guard_sim();
 
-       uint32_t facilitycode = 0, cardnumber = 0, fc = 0, cn = 0;
+       uint32_t facilitycode = 0, cardnumber = 0, fc = 0, cn = 0, fmtlen = 0;
        uint8_t clock = 64, encoding = 2, separator = 0, invert = 0;
        
        uint8_t bs[96];
        memset(bs, 0x00, sizeof(bs));
        
-       if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) return usage_lf_guard_sim();
+       if (sscanf(Cmd, "%u %u %u", &fmtlen, &fc, &cn ) != 2) return usage_lf_guard_sim();
 
+       fmtlen &= 0x7F;
        facilitycode = (fc & 0x000000FF);
        cardnumber = (cn & 0x0000FFFF);
        
-       if ( !GetGuardBits(facilitycode, cardnumber, bs)) {
+       if ( !GetGuardBits(fmtlen, facilitycode, cardnumber, bs)) {
                PrintAndLog("Error with tag bitstream generation.");
                return 1;
        }       
index 20530d171d94e3c60651d7186d0eba5ef0a11ed0..0424ed1780c5f3c64d9142c311c8feec940507a5 100644 (file)
@@ -185,7 +185,7 @@ int CmdIOSim(const char *Cmd) {
 
 int CmdIOClone(const char *Cmd) {
        
-       uint32_t blocks[3] = {T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_64 | 2<<T55x7_MAXBLOCK_SHIFT, 0, 0};
+       uint32_t blocks[3] = {T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_64 | 2 << T55x7_MAXBLOCK_SHIFT, 0, 0};
        uint16_t cn = 0;
        uint8_t version = 0, fc = 0;
        uint8_t bits[64];
@@ -206,9 +206,9 @@ int CmdIOClone(const char *Cmd) {
                PrintAndLog("Card Number Truncated to 16-bits (IOProx): %u", cn);
        }
        
-//     if (param_getchar(Cmd, 4) == 'Q' || param_getchar(Cmd, 4) == 'q')
+       if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q')
                //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
-//             blocks[0] = T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | 50<<T5555_BITRATE_SHIFT | 3<<T5555_MAXBLOCK_SHIFT;
+               blocks[0] = T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | ((50-2)>>1) << T5555_BITRATE_SHIFT | 2 << T5555_MAXBLOCK_SHIFT;
 
        if ( !getIOProxBits(version, fc, cn, bs)) {
                PrintAndLog("Error with tag bitstream generation.");
index f1da737db610f981e940a4c1098438c734694951..dc5e10d7f002555fd13eeb6b7132ed392722534b 100644 (file)
@@ -132,7 +132,7 @@ int CmdJablotronRead(const char *Cmd) {
 int CmdJablotronClone(const char *Cmd) {
 
        uint64_t fullcode = 0;
-       uint32_t blocks[3] = {T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_64 | 2<<T55x7_MAXBLOCK_SHIFT, 0, 0};
+       uint32_t blocks[3] = {T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_64 | 2 << T55x7_MAXBLOCK_SHIFT, 0, 0};
 
        uint8_t bits[64];
        uint8_t *bs = bits;
@@ -146,7 +146,7 @@ int CmdJablotronClone(const char *Cmd) {
        //Q5
        if (param_getchar(Cmd, 1) == 'Q' || param_getchar(Cmd, 1) == 'q') {
                //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
-               blocks[0] = T5555_MODULATION_BIPHASE | T5555_INVERT_OUTPUT | 64<<T5555_BITRATE_SHIFT | 2<<T5555_MAXBLOCK_SHIFT;
+               blocks[0] = T5555_MODULATION_BIPHASE | T5555_INVERT_OUTPUT | ((64-2)>>1) << T5555_BITRATE_SHIFT | 2 << T5555_MAXBLOCK_SHIFT;
        }
        
        // clearing the topbit needed for the preambl detection. 
index eeb0793918d749fd8e6fd3e0ae1c62215440ca40..8f5832ad92c5aa52f202ae06ea7b4f1c08e3ae46 100644 (file)
@@ -229,11 +229,11 @@ int CmdLFNedapClone(const char *Cmd) {
        ((ASK/DIphase   data rawdemod ab 0 64 1 0
        //NEDAP - compat mode, ASK/DIphase, data rate 64, 4 data blocks
        // DI-pahse (CDP) T55x7_MODULATION_DIPHASE
-       blocks[0] = T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_64 | 7<<T55x7_MAXBLOCK_SHIFT;
+       blocks[0] = T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_64 | 7 << T55x7_MAXBLOCK_SHIFT;
 
        if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q')
                //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
-               blocks[0] = T5555_MODULATION_BIPHASE | T5555_INVERT_OUTPUT | 64<<T5555_BITRATE_SHIFT | 7<<T5555_MAXBLOCK_SHIFT;
+               blocks[0] = T5555_MODULATION_BIPHASE | T5555_INVERT_OUTPUT | ((64-2)>>1) << T5555_BITRATE_SHIFT | 7 <<T5555_MAXBLOCK_SHIFT;
 
        blocks[1] = bytebits_to_byte(bs,32);
        blocks[2] = bytebits_to_byte(bs+32,32);
index 96c436556b38ee62a487da8f11ce7bb8e8af79d3..405d0d437ded85e9a5e2183d81961089a5dce499 100644 (file)
@@ -71,6 +71,18 @@ int getnoralsyBits(uint32_t id, uint16_t year, uint8_t *bits) {
        return 1;
 }
 
+/*
+*
+* 2520116 | BB0314FF2529900116360000 | 10111011 00000011 00010100 11111111 00100101 00101001 10010000 00000001 00010110 00110110 00000000 00000000
+*                      aaaaaaaaiii***iiiicc----                                       iiiiiiii iiiiYYYY YYYY**** iiiiiiii iiiiiiii cccccccc
+*
+* a = fixed value BB0314FF 
+* i = printed id, BCD-format
+* Y = year
+* c = checksum
+* 
+**/
+
 //see ASKDemod for what args are accepted
 int CmdNoralsyDemod(const char *Cmd) {
 
@@ -141,7 +153,7 @@ int CmdNoralsyClone(const char *Cmd) {
        
        uint16_t year = 0;
        uint32_t id = 0;
-       uint32_t blocks[4] = {T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_32 | T55x7_ST_TERMINATOR |3<<T55x7_MAXBLOCK_SHIFT, 0, 0};
+       uint32_t blocks[4] = {T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_32 | T55x7_ST_TERMINATOR | 3 << T55x7_MAXBLOCK_SHIFT, 0, 0};
        uint8_t bits[96];
        uint8_t *bs = bits;
        memset(bs, 0, sizeof(bits));
@@ -153,9 +165,9 @@ int CmdNoralsyClone(const char *Cmd) {
        year = param_get32ex(Cmd, 1, 2000, 10);
        
        //Q5
-       if (param_getchar(Cmd, 1) == 'Q' || param_getchar(Cmd, 1) == 'q') {
+       if (param_getchar(Cmd, 2) == 'Q' || param_getchar(Cmd, 2) == 'q') {
                //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
-               blocks[0] = T5555_MODULATION_MANCHESTER | 32<<T5555_BITRATE_SHIFT | T5555_ST_TERMINATOR | 3<<T5555_MAXBLOCK_SHIFT;
+               blocks[0] = T5555_MODULATION_MANCHESTER | ((32-2)>>1) << T5555_BITRATE_SHIFT | T5555_ST_TERMINATOR | 3 << T5555_MAXBLOCK_SHIFT;
        }
        
         if ( !getnoralsyBits(id, year, bs)) {
index accd6f22ebb624729756d4e3134d8d8550a8f8f9..84b6f4a26fc25d6c40dc81afd287d025309eb27f 100644 (file)
@@ -173,14 +173,14 @@ int CmdPrescoClone(const char *Cmd) {
 
        bool Q5 = false;
        uint32_t sitecode=0, usercode=0, fullcode=0;
-       uint32_t blocks[5] = {T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_32 | 4<<T55x7_MAXBLOCK_SHIFT | T55x7_ST_TERMINATOR, 0, 0, 0, 0};
+       uint32_t blocks[5] = {T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_32 | 4 << T55x7_MAXBLOCK_SHIFT | T55x7_ST_TERMINATOR, 0, 0, 0, 0};
        
        // get wiegand from printed number.
        if (GetWiegandFromPresco(Cmd, &sitecode, &usercode, &fullcode, &Q5) == -1) return usage_lf_presco_clone();
 
        if (Q5)
                //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
-               blocks[0] = T5555_MODULATION_MANCHESTER | 32<<T5555_BITRATE_SHIFT | 4<<T5555_MAXBLOCK_SHIFT | T5555_ST_TERMINATOR;
+               blocks[0] = T5555_MODULATION_MANCHESTER | ((32-2)>>1) << T5555_BITRATE_SHIFT | 4 << T5555_MAXBLOCK_SHIFT | T5555_ST_TERMINATOR;
 
        if ((sitecode & 0xFF) != sitecode) {
                sitecode &= 0xFF;
index b6c8ed6a600c9eeba59a0d99e40c958ae1707a10..33fd10c6371447f02f1d303b81aa6a866170f61a 100644 (file)
@@ -100,11 +100,11 @@ int CmdPyramidClone(const char *Cmd) {
        }       
 
        //Pyramid - compat mode, FSK2a, data rate 50, 4 data blocks
-       blocks[0] = T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 4<<T55x7_MAXBLOCK_SHIFT;
+       blocks[0] = T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 4 << T55x7_MAXBLOCK_SHIFT;
 
-       if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q')
+       if (param_getchar(Cmd, 2) == 'Q' || param_getchar(Cmd, 2) == 'q')
                //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
-               blocks[0] = T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | 50<<T5555_BITRATE_SHIFT | 4<<T5555_MAXBLOCK_SHIFT;
+               blocks[0] = T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | ((50-2)>>1) << T5555_BITRATE_SHIFT | 4 << T5555_MAXBLOCK_SHIFT;
 
        blocks[1] = bytebits_to_byte(bs,32);
        blocks[2] = bytebits_to_byte(bs+32,32);
index 42e1a00ff88e1519898e38aed5333cca5cd70bae..c08371087789997a3e39c0b8bddfb693e73e2465 100644 (file)
@@ -45,6 +45,17 @@ static uint8_t visa_chksum( uint32_t id ) {
     return sum & 0xF;
 }
 
+/**
+*
+* 56495332 00096ebd 00000077 —> tag id 618173
+* aaaaaaaa iiiiiiii -----..c
+*
+* a = fixed value  ascii 'VIS2'
+* i = card id
+* c = checksum  (xor of card id)
+* . = unknown 
+* 
+**/
 //see ASKDemod for what args are accepted
 int CmdVisa2kDemod(const char *Cmd) {
 
@@ -82,7 +93,7 @@ int CmdVisa2kDemod(const char *Cmd) {
        uint32_t raw1 = bytebits_to_byte(DemodBuffer, 32);
        uint32_t raw2 = bytebits_to_byte(DemodBuffer+32, 32);
        uint32_t raw3 = bytebits_to_byte(DemodBuffer+64, 32);
-
+       
        // chksum
        uint8_t calc = visa_chksum(raw2);
        uint8_t chk = raw3 & 0xF;       
@@ -106,7 +117,7 @@ int CmdVisa2kRead(const char *Cmd) {
 int CmdVisa2kClone(const char *Cmd) {
 
        uint64_t id = 0;
-       uint32_t blocks[4] = {T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_64 | T55x7_ST_TERMINATOR |3<<T55x7_MAXBLOCK_SHIFT, BL0CK1, 0};
+       uint32_t blocks[4] = {T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_64 | T55x7_ST_TERMINATOR | 3 << T55x7_MAXBLOCK_SHIFT, BL0CK1, 0};
 
        char cmdp = param_getchar(Cmd, 0);
        if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_visa2k_clone();
@@ -116,7 +127,7 @@ int CmdVisa2kClone(const char *Cmd) {
        //Q5
        if (param_getchar(Cmd, 1) == 'Q' || param_getchar(Cmd, 1) == 'q') {
                //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
-               blocks[0] = T5555_MODULATION_MANCHESTER | 64<<T5555_BITRATE_SHIFT | T5555_ST_TERMINATOR | 3<<T5555_MAXBLOCK_SHIFT;
+               blocks[0] = T5555_MODULATION_MANCHESTER | ((64-2)>>1) << T5555_BITRATE_SHIFT | T5555_ST_TERMINATOR | 3 << T5555_MAXBLOCK_SHIFT;
        }
        
        // 
Impressum, Datenschutz