]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdlfpresco.c
fix: some compiler warning when the #define is not matching.
[proxmark3-svn] / client / cmdlfpresco.c
index d6a324480c5e715016a47cd9d002179bc3bab9ad..84b6f4a26fc25d6c40dc81afd287d025309eb27f 100644 (file)
@@ -45,6 +45,8 @@ int GetWiegandFromPresco(const char *Cmd, uint32_t *sitecode, uint32_t *usercode
        uint8_t cmdp = 0;
        char id[11];
        int stringlen = 0;
+       memset(id, 0x00, sizeof(id));
+       
        while(param_getchar(Cmd, cmdp) != 0x00) {
                switch(param_getchar(Cmd, cmdp)) {
                        case 'h':
@@ -52,7 +54,7 @@ int GetWiegandFromPresco(const char *Cmd, uint32_t *sitecode, uint32_t *usercode
                        case 'H':
                                hex = true;
                                //get hex
-                               *fullcode = param_get32ex(Cmd, cmdp+1, 0, 10);
+                               *fullcode = param_get32ex(Cmd, cmdp+1, 0, 16);
                                cmdp+=2;
                                break;
                        case 'P':
@@ -81,19 +83,19 @@ int GetWiegandFromPresco(const char *Cmd, uint32_t *sitecode, uint32_t *usercode
        if(errors) return -1;
 
        if (!hex) {
-       for (int index =0; index < strlen(id); ++index) {
-               
-               // Get value from number string.
-               if ( id[index] == '*' ) val = 10;
-               if ( id[index] == '#')  val = 11;               
-               if ( id[index] >= 0x30 && id[index] <= 0x39 )
-                       val = id[index] - 0x30;
-               
-                       *fullcode += val;
+               for (int index =0; index < strlen(id); ++index) {
                
-               // last digit is only added, not multipled.
-               if ( index < strlen(id)-1 ) 
-                               *fullcode *= 12;
+                       // Get value from number string.
+                       if ( id[index] == '*' ) val = 10;
+                       if ( id[index] == '#')  val = 11;               
+                       if ( id[index] >= 0x30 && id[index] <= 0x39 )
+                               val = id[index] - 0x30;
+                       
+                               *fullcode += val;
+                       
+                       // last digit is only added, not multipled.
+                       if ( index < strlen(id)-1 ) 
+                                       *fullcode *= 12;
                }
        }
 
@@ -113,34 +115,43 @@ int GetPrescoBits(uint32_t fullcode, uint8_t *prescoBits) {
 
 //see ASKDemod for what args are accepted
 int CmdPrescoDemod(const char *Cmd) {
-       if (!ASKDemod(Cmd, false, false, 1)) {
-               if (g_debugMode) PrintAndLog("ASKDemod failed");
+       bool st = true;
+       if (!ASKDemod_ext("32 0 0 0 0 a", FALSE, FALSE, 1, &st)) {
+               if (g_debugMode) PrintAndLog("DEBUG: Error Presco ASKDemod failed");
                return 0;
        }
        size_t size = DemodBufferLen;
-       //call lfdemod.c demod for Viking
+       //call lfdemod.c demod for Presco
        int ans = PrescoDemod(DemodBuffer, &size);
        if (ans < 0) {
-               if (g_debugMode) PrintAndLog("Error Presco_Demod %d", ans);
+               if (g_debugMode){
+                       if (ans == -1)
+                               PrintAndLog("DEBUG: Error - Presco: too few bits found");
+                       else if (ans == -2)
+                               PrintAndLog("DEBUG: Error - Presco: preamble not found");
+                       else if (ans == -3)
+                               PrintAndLog("DEBUG: Error - Presco: Size not correct: %d", size);
+                       else
+                               PrintAndLog("DEBUG: Error - Presco: ans: %d", ans);
+               }
                return 0;
        }
+       setDemodBuf(DemodBuffer, 128, ans);
+       
        //got a good demod
-       uint32_t raw1 = bytebits_to_byte(DemodBuffer+ans, 32);
-       uint32_t raw2 = bytebits_to_byte(DemodBuffer+ans+32, 32);
-       uint32_t raw3 = bytebits_to_byte(DemodBuffer+ans+64, 32);
-       uint32_t raw4 = bytebits_to_byte(DemodBuffer+ans+96, 32);
+       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);
+       uint32_t raw4 = bytebits_to_byte(DemodBuffer+96, 32);
        uint32_t cardid = raw4;
-       PrintAndLog("Presco Tag Found: Card ID %08X", cardid);
-       PrintAndLog("Raw: %08X%08X%08X%08X", raw1,raw2,raw3,raw4);
-       setDemodBuf(DemodBuffer+ans, 128, 0);
-       
+       PrintAndLog("Presco Tag Found: Card ID %08X, Raw: %08X%08X%08X%08X", cardid, raw1, raw2, raw3, raw4);
+
        uint32_t sitecode = 0, usercode = 0, fullcode = 0;
-       bool Q5=false;
+       bool Q5 = false;
        char cmd[12] = {0};
        sprintf(cmd, "H %08X", cardid);
        GetWiegandFromPresco(cmd, &sitecode, &usercode, &fullcode, &Q5);
        PrintAndLog("SiteCode %u, UserCode %u, FullCode, %08X", sitecode, usercode, fullcode);
-       
        return 1;
 }
 
@@ -151,7 +162,7 @@ int CmdPrescoRead(const char *Cmd) {
        // read lf silently
        CmdLFRead("s");
        // get samples silently
-       getSamples("30000",false);
+       getSamples("12000", TRUE);
        // demod and output Presco ID   
        return CmdPrescoDemod(Cmd);
 }
@@ -162,13 +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, 5};
+       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)
-               blocks[0] = T5555_MODULATION_MANCHESTER | 32<<T5555_BITRATE_SHIFT | 4<<T5555_MAXBLOCK_SHIFT | T5555_ST_TERMINATOR;
+               //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
+               blocks[0] = T5555_MODULATION_MANCHESTER | ((32-2)>>1) << T5555_BITRATE_SHIFT | 4 << T5555_MAXBLOCK_SHIFT | T5555_ST_TERMINATOR;
 
        if ((sitecode & 0xFF) != sitecode) {
                sitecode &= 0xFF;
@@ -202,7 +214,7 @@ int CmdPrescoClone(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;
                }
@@ -236,8 +248,8 @@ int CmdPrescoSim(const char *Cmd) {
 static command_t CommandTable[] = {
     {"help",   CmdHelp,                1, "This help"},
        {"read",        CmdPrescoRead,  0, "Attempt to read and Extract tag data"},
-       {"clone", CmdPrescoClone, 0, "d <9 digit ID> or h <hex> [Q5] clone presco tag"},
-       {"sim",   CmdPrescoSim,   0, "d <9 digit ID> or h <hex> simulate presco tag"},
+       {"clone",       CmdPrescoClone, 0, "d <9 digit ID> or h <hex> [Q5] clone presco tag"},
+       {"sim",         CmdPrescoSim,   0, "d <9 digit ID> or h <hex> simulate presco tag"},
     {NULL, NULL, 0, NULL}
 };
 
Impressum, Datenschutz