]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdlfguard.c
updated
[proxmark3-svn] / client / cmdlfguard.c
index 828bdb6827853f4b5a6c3a355d3ab7a318e3d859..d9010a19a2209e99045f4dab5ba84a3092500e04 100644 (file)
@@ -6,8 +6,7 @@
 //-----------------------------------------------------------------------------
 // Low frequency Farpoint / Pyramid tag commands
 //-----------------------------------------------------------------------------
-#include <string.h>
-#include <inttypes.h>
+
 #include "cmdlfguard.h"
 static int CmdHelp(const char *Cmd);
 
@@ -40,7 +39,6 @@ int usage_lf_guard_sim(void) {
        return 0;
 }
 
-
 // Works for 26bits.
 int GetGuardBits(uint32_t fc, uint32_t cn, uint8_t *guardBits) {
   
@@ -48,10 +46,8 @@ int GetGuardBits(uint32_t fc, uint32_t cn, uint8_t *guardBits) {
        time_t t;
        srand((unsigned) time(&t));
        //uint8_t xorKey = rand() % 0xFF;
-       uint8_t xorKey = 0x6b;
+       uint8_t xorKey = 0x66;
        uint8_t i;
-       
-       
        uint8_t pre[96];
        memset(pre, 0x00, sizeof(pre));
 
@@ -91,12 +87,6 @@ int GetGuardBits(uint32_t fc, uint32_t cn, uint8_t *guardBits) {
        
        if (g_debugMode) printf(" WIE | %s\n", sprint_hex(rawbytes, sizeof(rawbytes))); 
        
-       // NIBBLE_SWAP (works on all data)
-       // for (i = 0; i < 12; ++i)
-               // rawbytes[i] = SWAP_NIBBLE( rawbytes[i] );
-
-       // printf("SWAP | %s\n", sprint_hex(rawbytes, sizeof(rawbytes)));
-       
        // XOR (only works on wiegand stuff)
        for (i = 1; i < 12; ++i)
                rawbytes[i] ^= xorKey ;
@@ -111,7 +101,7 @@ int GetGuardBits(uint32_t fc, uint32_t cn, uint8_t *guardBits) {
        if (g_debugMode) printf(" Raw | %s\n", sprint_bin(pre, 64) );
        
        // add spacer bit 0 every 4 bits, starting with index 0,
-       // 12 bytes, 24 nibbles.  24+1 extra bites. 3bytes.  Ie 9bytes | 1byte xorkey, 8bytes rawdata (64bits, should be enough for a 40bit wiegand)
+       // 12 bytes, 24 nibbles.  24+1 extra bites. 3bytes.  ie 9bytes | 1byte xorkey, 8bytes rawdata (64bits, should be enough for a 40bit wiegand)
        addParity(pre, guardBits+6, 64, 5, 3);
 
        // preamble
@@ -121,10 +111,6 @@ int GetGuardBits(uint32_t fc, uint32_t cn, uint8_t *guardBits) {
        guardBits[3] = 1;
        guardBits[4] = 1;
        guardBits[5] = 0;
-/*               6      B      
-PRE |          0110   1101   0101   1110   0001   1101   1101   0111   1101011011010110110101101101011
-FIN | 111110 0 0110 0 1101 0 0101 0 1110 0 0001 0 1101 0 1101 0 0111 0 110100110011010011001101001100110100110000000000
-*/
        
        if (g_debugMode) printf(" FIN | %s\n", sprint_bin(guardBits, 96) );
        return 1;
@@ -132,7 +118,7 @@ FIN | 111110 0 0110 0 1101 0 0101 0 1110 0 0001 0 1101 0 1101 0 0111 0 110100110
 
 int CmdGuardRead(const char *Cmd) {
        CmdLFRead("s");
-       getSamples("30000",false);
+       getSamples("12000", TRUE);
        return CmdG_Prox_II_Demod("");
 }
 
@@ -150,6 +136,7 @@ int CmdGuardClone(const char *Cmd) {
        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 (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) return usage_lf_guard_clone();
@@ -170,7 +157,7 @@ int CmdGuardClone(const char *Cmd) {
        PrintAndLog("Blk | Data ");
        PrintAndLog("----+------------");
        for ( i = 0; i<4; ++i )
-               PrintAndLog(" %02d | %08x", i, blocks[i]);
+               PrintAndLog(" %02d | 0x%08x", i, blocks[i]);
 
        UsbCommand resp;
        UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}};
@@ -180,7 +167,7 @@ int CmdGuardClone(const char *Cmd) {
                c.arg[1] = i;
                clearCommandBuffer();
                SendCommand(&c);
-               if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){
+               if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)){
                        PrintAndLog("Error occurred, device did not respond during write operation.");
                        return -1;
                }
@@ -194,16 +181,11 @@ int CmdGuardSim(const char *Cmd) {
        if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_guard_sim();
 
        uint32_t facilitycode = 0, cardnumber = 0, fc = 0, cn = 0;
+       uint8_t clock = 64, encoding = 2, separator = 0, invert = 0;
        
        uint8_t bs[96];
-       size_t size = sizeof(bs);
-       memset(bs, 0x00, size);
+       memset(bs, 0x00, sizeof(bs));
        
-       // Pyramid uses:  ASK Biphase, clk: 32, invert: 0
-       uint64_t arg1, arg2;
-       arg1 = (10 << 8) + 8;
-       arg2 = 32 | 0;
-
        if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) return usage_lf_guard_sim();
 
        facilitycode = (fc & 0x000000FF);
@@ -215,9 +197,20 @@ int CmdGuardSim(const char *Cmd) {
        }       
 
        PrintAndLog("Simulating Guardall - Facility Code: %u, CardNumber: %u", facilitycode, cardnumber );
-       
+
+       // Guard uses:  clk: 64, invert: 0, encoding: 2 (ASK Biphase)
+       uint64_t arg1, arg2;
+       arg1 = (clock << 8) | encoding;
+       arg2 = (invert << 8) | separator;
+
+       uint8_t rawbytes[12];
+       size_t size = sizeof(rawbytes);
+       for (uint8_t i=0; i < size; ++i){
+               rawbytes[i] =  bytebits_to_byte( bs + (i*8), 8);
+       }
+
        UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
-       memcpy(c.d.asBytes, bs, size);
+       memcpy(c.d.asBytes, rawbytes, size );
        clearCommandBuffer();
        SendCommand(&c);
        return 0;
@@ -227,7 +220,7 @@ static command_t CommandTable[] = {
     {"help",   CmdHelp,                1, "This help"},
        {"read",        CmdGuardRead,  0, "Attempt to read and extract tag data"},
        {"clone",       CmdGuardClone, 0, "<Facility-Code> <Card Number>  clone Guardall tag"},
-//     {"sim",         CmdGuardSim,   0, "<Facility-Code> <Card Number>  simulate Guardall tag"},
+       {"sim",         CmdGuardSim,   0, "<Facility-Code> <Card Number>  simulate Guardall tag"},
     {NULL, NULL, 0, NULL}
 };
 
Impressum, Datenschutz